Skip to content

Commit 86e3bc6

Browse files
committed
feat: allow to disable debounce
Fixed #24, Fixed #9
1 parent fbb4a2a commit 86e3bc6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib/CodeMirror.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
export let readonly = false;
3333
export let placeholder: string | HTMLElement | null | undefined = undefined;
3434
35+
export let nodebounce = false;
36+
3537
const is_browser = typeof window !== "undefined";
3638
const dispatch = createEventDispatcher<{ change: string }>();
3739
@@ -52,12 +54,12 @@
5254
$: view && update(value);
5355
$: view && state_extensions && reconfigure();
5456
57+
$: on_change = nodebounce ? handle_change : debounce(handle_change, 300);
58+
5559
onMount(() => (view = create_editor_view()));
5660
onDestroy(() => view?.destroy());
5761
5862
function create_editor_view(): EditorView {
59-
const on_change = debounce(handle_change, 300);
60-
6163
return new EditorView({
6264
parent: element,
6365
state: create_editor_state(value),

src/routes/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
placeholder: null,
2121
lang: null,
2222
theme: null,
23+
nodebounce: false
2324
};
2425
2526
const languages = ["custom", "javascript", "typescript", "css", "html"];
@@ -86,6 +87,10 @@
8687
<input id="lineWrapping" type="checkbox" bind:checked={props.lineWrapping} />
8788
<label for="lineWrapping">Line Wrapping</label>
8889
</div>
90+
<div class="toggle">
91+
<input id="nodebounce" type="checkbox" bind:checked={props.nodebounce} />
92+
<label for="nodebounce">No debounce</label>
93+
</div>
8994
</div>
9095

9196
<h5>Tab</h5>

0 commit comments

Comments
 (0)