Skip to content

Commit 99d331f

Browse files
committed
feat: add lineWrapping option
resolve #1
1 parent 22e0b5a commit 99d331f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/lib/CodeMirror.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
export let tabSize = 2;
2828
2929
export let styles: ThemeSpec | null | undefined = undefined;
30+
export let lineWrapping = false;
3031
export let editable = true;
3132
export let readonly = false;
3233
export let placeholder: string | HTMLElement | null | undefined = undefined;
@@ -43,7 +44,7 @@
4344
let first_update = true;
4445
4546
$: state_extensions = [
46-
...get_base_extensions(basic, useTab, tabSize, placeholder, editable, readonly, lang),
47+
...get_base_extensions(basic, useTab, tabSize, lineWrapping, placeholder, editable, readonly, lang),
4748
...get_theme(theme, styles),
4849
...extensions,
4950
];
@@ -120,6 +121,7 @@
120121
basic: boolean,
121122
useTab: boolean,
122123
tabSize: number,
124+
lineWrapping: boolean,
123125
placeholder: string | HTMLElement | null | undefined,
124126
editable: boolean,
125127
readonly: boolean,
@@ -135,6 +137,7 @@
135137
if (useTab) extensions.push(keymap.of([indentWithTab]));
136138
if (placeholder) extensions.push(placeholderExt(placeholder));
137139
if (lang) extensions.push(lang);
140+
if (lineWrapping) extensions.push(EditorView.lineWrapping);
138141
139142
return extensions;
140143
}

src/routes/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
basic: true,
1515
useTab: true,
1616
editable: true,
17+
lineWrapping: false,
1718
readonly: false,
1819
tabSize: 2,
1920
placeholder: null,
@@ -81,6 +82,10 @@
8182
<input id="readonly" type="checkbox" bind:checked={props.readonly} />
8283
<label for="readonly">Read-only</label>
8384
</div>
85+
<div class="toggle">
86+
<input id="lineWrapping" type="checkbox" bind:checked={props.lineWrapping} />
87+
<label for="lineWrapping">Line Wrapping</label>
88+
</div>
8489
</div>
8590

8691
<h5>Tab</h5>

0 commit comments

Comments
 (0)