Skip to content

Commit 0733553

Browse files
committed
[BREAKING CHANGE] editable prop become to disabled (revere value).
[BREAKING CHANGE] `lint-gutter` prop become `gutter`. Add gutter-config prop.
1 parent 1de388f commit 0733553

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This component can handle bidirectional binding by `v-model` like a general Vue
3636
| tab | boolean | Enables tab indentation. |
3737
| theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use [@codemirror/theme-one-dark](https://github.com/codemirror/theme-one-dark), import `oneDark` and put it in this prop. |
3838
| readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
39-
| disabled | boolean | When this is set to true, it is similar to `readonly`, except that the cursor is not displayed like the normal pre tag. |
39+
| disabled | boolean | This is the reversed value of the CodeMirror editable. Similar to `readonly`, but setting this value to true disables dragging. |
4040
| lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
4141
| phrases | Record&lt;string, string&gt; | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
4242
| extensions | Extension[] | Includes enhancements to extend CodeMirror. |

dev/DemoPage.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default defineComponent({
275275
:lang="cmLangJs"
276276
:linter="cmLintJs"
277277
:dark="dark"
278-
lint-gutter
278+
gutter
279279
warp
280280
basic
281281
/>
@@ -302,10 +302,11 @@ export default defineComponent({
302302
</a>
303303
and
304304
<a
305-
href="https://codemirror.net/docs/ref/#state.EditorState^readOnly"
305+
href="https://codemirror.net/docs/ref/#view.EditorView%5Eeditable"
306306
target="_blank"
307307
>
308308
<code>editable</code>
309+
(not disabled)
309310
</a>
310311
a demo
311312
</h2>
@@ -332,20 +333,20 @@ export default defineComponent({
332333
</div>
333334
<div class="form-check form-switch">
334335
<input
335-
id="editable"
336-
v-model="isEditable"
336+
id="disabled"
337+
v-model="isDisabled"
337338
type="checkbox"
338339
class="form-check-input"
339340
role="switch"
340-
:aria-checked="isEditable"
341+
:aria-checked="isDisabled"
341342
/>
342-
<label class="form-check-label" for="editable">Editable</label>
343+
<label class="form-check-label" for="disabled">Disabled</label>
343344
</div>
344345
<code-mirror
345346
:dark="dark"
346347
basic
347348
:readonly="isReadonly"
348-
:editable="isEditable"
349+
:disabled="isDisabled"
349350
>
350351
<pre>
351352
色は匂へど 散りぬるを
@@ -424,8 +425,8 @@ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deseru
424425
425426
/** Readonly */
426427
const isReadonly = ref(true);
427-
/** Editable */
428-
const isEditable = ref(true);
428+
/** Disabled */
429+
const isDisabled = ref(false);
429430
430431
// Realtime convert Markdown
431432
watch(demo, async current => {
@@ -452,7 +453,7 @@ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deseru
452453
onViewUpdate,
453454
onReady,
454455
isReadonly,
455-
isEditable,
456+
isDisabled,
456457
};
457458
},
458459
});

src/components/CodeMirror.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
onUnmounted,
77
ref,
88
shallowRef,
9-
toRaw,
109
watch,
1110
type ComputedRef,
1211
type ObjectEmitsOptions,
@@ -113,14 +112,15 @@ export default defineComponent({
113112
/**
114113
* Line wrapping
115114
*
115+
* An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
116116
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
117117
*/
118118
wrap: {
119119
type: Boolean,
120120
default: false,
121121
},
122122
/**
123-
* Tab handling
123+
* Allow tab input.
124124
*
125125
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
126126
*/
@@ -138,13 +138,16 @@ export default defineComponent({
138138
default: false,
139139
},
140140
/**
141-
* Editable
141+
* Disable input.
142+
*
143+
* This is the reversed value of the CodeMirror editable.
144+
* Similar to `readonly`, but setting this value to true disables dragging.
142145
*
143146
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
144147
*/
145-
editable: {
148+
disabled: {
146149
type: Boolean,
147-
default: true,
150+
default: false,
148151
},
149152
/**
150153
* Additional Extension
@@ -184,11 +187,22 @@ export default defineComponent({
184187
type: Function as PropType<LintSource>,
185188
default: undefined,
186189
},
187-
/** Show Gutter */
188-
lintGutter: {
190+
/**
191+
* Show Linter Gutter
192+
*
193+
* An area to circle the lines with errors will be displayed.
194+
*/
195+
gutter: {
189196
type: Boolean,
190197
defalt: false,
191198
},
199+
/**
200+
* Gutter Config
201+
*/
202+
gutterConfig: {
203+
type: Object,
204+
default: () => undefined,
205+
},
192206
/** Using tag */
193207
tag: {
194208
type: String,
@@ -264,13 +278,15 @@ export default defineComponent({
264278
// Readonly option
265279
EditorState.readOnly.of(props.readonly),
266280
// Editable option
267-
EditorView.editable.of(props.editable),
281+
EditorView.editable.of(!props.disabled),
268282
// Lang
269-
props.lang ? toRaw(props.lang) : undefined,
283+
props.lang ? props.lang : undefined,
270284
// Append Linter settings
271285
props.linter ? linter(props.linter) : undefined,
272286
// Show 🔴 to error line when linter enabled.
273-
props.linter && props.lintGutter ? lintGutter() : undefined,
287+
props.linter && props.gutter
288+
? lintGutter(props.gutterConfig)
289+
: undefined,
274290
// Append Extensions (such as basic-setup)
275291
...props.extensions,
276292
])
@@ -297,17 +313,15 @@ export default defineComponent({
297313
);
298314

299315
// Extension (mostly props) Changed
300-
watch(extensions, e => {
316+
watch(extensions, exts =>
301317
// TODO: Reduce unchanched value
302318
view.value.dispatch({
303-
effects: StateEffect.reconfigure.of(e),
304-
});
305-
});
319+
effects: StateEffect.reconfigure.of(exts),
320+
})
321+
);
306322

307323
// focus changed
308-
watch(focus, isFocus => {
309-
context.emit('focus', isFocus);
310-
});
324+
watch(focus, isFocus => context.emit('focus', isFocus));
311325

312326
/** When loaded */
313327
onMounted(async () => {

0 commit comments

Comments
 (0)