-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathKeymap.js
More file actions
50 lines (43 loc) · 1.21 KB
/
Keymap.js
File metadata and controls
50 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { Extension } from '@tiptap/core'
import { Plugin } from '@tiptap/pm/state'
const Keymap = Extension.create({
name: 'customkeymap',
addKeyboardShortcuts() {
return {
/**
* <Backspace>
* Allows to undo input rules after they got automatically applied
*/
Backspace: () => this.editor.commands.undoInputRule(),
}
},
addProseMirrorPlugins() {
return [
new Plugin({
props: {
handleKeyDown(view, event) {
const key = event.key || event.keyCode
if ((event.ctrlKey || event.metaKey) && !event.shiftKey && (key === 'f' || key === 70)) {
// We need to stop propagation and dispatch the event on the window
// in order to force triggering the browser native search in the text editor
event.stopPropagation()
window.dispatchEvent(event)
return true
}
if (event.key === 'Delete' && event.ctrlKey === true) {
// Prevent deleting the file, by core Viewer.vue
event.stopPropagation()
window.dispatchEvent(event)
return true
}
},
},
}),
]
},
})
export default Keymap