Skip to content

Commit 1910d83

Browse files
committedJul 21, 2022
styles: improve component
1 parent c5ea755 commit 1910d83

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed
 

‎src/codemirror.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ export const createEditorState = ({ onUpdate, onChange, onFocus, onBlur, ...conf
3333
})
3434
}
3535

36+
export const createEditorView = (config: EditorViewConfig) => new EditorView({ ...config })
3637
export const destroyEditorView = (view: EditorView) => view.destroy()
37-
export const createEditorView = (config: EditorViewConfig) => {
38-
return new EditorView({ ...config })
39-
}
4038

4139
// https://codemirror.net/examples/config/
4240
// https://github.com/uiwjs/react-codemirror/blob/22cc81971a/src/useCodeMirror.ts#L144
@@ -61,10 +59,7 @@ export const createEditorExtensionToggler = (view: EditorView, extension: Extens
6159
}
6260
}
6361

64-
export const createEditorTools = (view: EditorView) => {
65-
// UE state
66-
const focus = () => view.focus()
67-
62+
export const getEditorTools = (view: EditorView) => {
6863
// doc state
6964
const getDoc = () => view.state.doc.toString()
7065
const setDoc = (newDoc: string) => {
@@ -79,6 +74,9 @@ export const createEditorTools = (view: EditorView) => {
7974
}
8075
}
8176

77+
// UX operations
78+
const focus = () => view.focus()
79+
8280
// reconfigure extension
8381
const { run: reExtensions } = createEditorCompartment(view)
8482

‎src/component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineComponent, shallowRef, computed, watch, toRaw, onMounted, onBeforeUnmount, h } from 'vue'
22
import { EditorState } from '@codemirror/state'
33
import { EditorView } from '@codemirror/view'
4-
import { createEditorState, createEditorView, createEditorTools, destroyEditorView } from './codemirror'
4+
import { createEditorState, createEditorView, destroyEditorView, getEditorTools } from './codemirror'
55
import { useGlobalConfig, DEFAULT_CONFIG } from './config'
66
import { props, ConfigProps } from './props'
77
import { events, EventKey } from './events'
@@ -57,7 +57,7 @@ export default defineComponent({
5757
root: config.value.root
5858
})
5959

60-
const editorTools = createEditorTools(view.value)
60+
const editorTools = getEditorTools(view.value)
6161

6262
// watch prop.modelValue
6363
watch(

0 commit comments

Comments
 (0)
Please sign in to comment.