Skip to content

Commit

Permalink
Move search handler for text to only trigger within the text input
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 25, 2020
1 parent 5239746 commit 52a20e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
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
}
},
},
})]
}

}

0 comments on commit 52a20e2

Please sign in to comment.