Skip to content

Commit

Permalink
styles: improve component
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Jul 21, 2022
1 parent c5ea755 commit 1910d83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ export const createEditorState = ({ onUpdate, onChange, onFocus, onBlur, ...conf
})
}

export const createEditorView = (config: EditorViewConfig) => new EditorView({ ...config })
export const destroyEditorView = (view: EditorView) => view.destroy()
export const createEditorView = (config: EditorViewConfig) => {
return new EditorView({ ...config })
}

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

export const createEditorTools = (view: EditorView) => {
// UE state
const focus = () => view.focus()

export const getEditorTools = (view: EditorView) => {
// doc state
const getDoc = () => view.state.doc.toString()
const setDoc = (newDoc: string) => {
Expand All @@ -79,6 +74,9 @@ export const createEditorTools = (view: EditorView) => {
}
}

// UX operations
const focus = () => view.focus()

// reconfigure extension
const { run: reExtensions } = createEditorCompartment(view)

Expand Down
4 changes: 2 additions & 2 deletions src/component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent, shallowRef, computed, watch, toRaw, onMounted, onBeforeUnmount, h } from 'vue'
import { EditorState } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
import { createEditorState, createEditorView, createEditorTools, destroyEditorView } from './codemirror'
import { createEditorState, createEditorView, destroyEditorView, getEditorTools } from './codemirror'
import { useGlobalConfig, DEFAULT_CONFIG } from './config'
import { props, ConfigProps } from './props'
import { events, EventKey } from './events'
Expand Down Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
root: config.value.root
})

const editorTools = createEditorTools(view.value)
const editorTools = getEditorTools(view.value)

// watch prop.modelValue
watch(
Expand Down

0 comments on commit 1910d83

Please sign in to comment.