diff --git a/src/components/code-editor.vue b/src/components/code-editor.vue index 7b43ece..84209bf 100644 --- a/src/components/code-editor.vue +++ b/src/components/code-editor.vue @@ -21,13 +21,15 @@ export default { watch: { code(v) { let doc = this.$view.state.doc + let { anchor } = this.$view.state.selection.main this.$view.dispatch({ changes: { from: 0, to: doc.length, insert: v - } + }, + selection: { anchor } // 恢复之前的光标位置 }) } }, @@ -49,12 +51,12 @@ export default { EditorView.lineWrapping, // 监听代码变化 EditorView.updateListener.of(v => { - let value = v.state.doc.toString().trim() - if (!this.$last || value === this.$last) { - this.$last = value + let value = v.state.doc.toString() + if (!this.$last || value.trim() === this.$last) { + this.$last = value.trim() return } - this.$last = value + this.$last = value.trim() this.$emit('change', value, lang) }) ), @@ -75,5 +77,6 @@ export default { .cm-editor { width: 100%; height: 100%; + outline: none !important; } diff --git a/src/pages/playground/app.vue b/src/pages/playground/app.vue index d8679bd..aa0fa67 100644 --- a/src/pages/playground/app.vue +++ b/src/pages/playground/app.vue @@ -12,7 +12,7 @@ - + @@ -23,35 +23,6 @@ import Preview from './views/preview.vue' import { gzip, ungzip } from '@bytedo/gzip' -const template = ` - - - - - - - {{css}} -