MCPcopy Create free account
hub / github.com/editablejs/editable / withShortcuts

Function withShortcuts

packages/plugins/image/src/plugin/with-shortcuts.ts:51–79  ·  view source on GitHub ↗
(editor: Editable)

Source from the content-addressed store, hash-verified

49 }
50}
51export const withShortcuts = (editor: Editable) => {
52 const { onKeydown } = editor
53
54 editor.onKeydown = event => {
55 const { selection } = editor
56 if (
57 selection &&
58 Range.isCollapsed(selection) &&
59 !Editable.isComposing(editor) &&
60 Hotkey.match('space', event)
61 ) {
62 const anchor = Range.start(selection)
63 const match = findMatchedRange(editor, anchor)
64 if (match) {
65 event.preventDefault()
66 const { range, url } = match
67 Transforms.delete(editor, {
68 at: range,
69 })
70 Transforms.collapse(editor)
71 ImageEditor.insert(editor, {
72 file: url,
73 })
74 return
75 }
76 }
77 onKeydown(event)
78 }
79}

Callers 1

withImageFunction · 0.90

Calls 1

findMatchedRangeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…