import { EditorSelection } from '@codemirror/state'; import { ICommand } from '.'; export const image: ICommand = { name: 'image', keyCommand: 'image', button: { 'aria-label': 'Add image text' }, icon: ( ), execute: ({ state, view }) => { if (!state || !view) return; const main = view.state.selection.main; const txt = view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to); view.dispatch({ changes: { from: main.from, to: main.to, insert: `![](${txt})`, }, selection: EditorSelection.range(main.from + 4, main.to + 4), // selection: { anchor: main.from + 4 }, }); }, };