Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move search handler for text to only trigger within the text input
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 25, 2020
commit 52a20e28ba01add51e9b28c8a7128dc2af340162
11 changes: 1 addition & 10 deletions src/components/EditorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,12 @@ export default {
this.saveStatusPolling = setInterval(() => {
this.updateLastSavedStatus()
}, 2000)
document.addEventListener('keydown', this._keyUpHandler, true)
},
beforeDestroy() {
this.close()
},
methods: {
async close() {
document.removeEventListener('keydown', this._keyUpHandler, true)
clearInterval(this.saveStatusPolling)
if (this.currentSession && this.syncService) {
try {
Expand Down Expand Up @@ -326,7 +324,7 @@ export default {
},
}),
new Keymap({
'Ctrl-s': () => {
'Mod-s': () => {
this.syncService.save()
return true
},
Expand Down Expand Up @@ -465,13 +463,6 @@ export default {
}
}
},
_keyUpHandler(event) {
const key = event.key || event.keyCode
if ((event.ctrlKey || event.metaKey) && !event.shiftKey && (key === 'f' || key === 70)) {
event.stopPropagation()
return true
}
},
},
}
</script>
Expand Down
21 changes: 19 additions & 2 deletions src/extensions/Keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,33 @@
*
*/

import { Extension } from 'tiptap'
import { Extension, Plugin } from 'tiptap'

export default class Keymap extends Extension {

get name() {
return 'save'
return 'customkeymap'
}

keys({ schema }) {
return this.options
}

get plugins() {
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
}
},
},
})]
}

}