Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only overwrite Ctrl-f when text is focussed #988

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js.map

Large diffs are not rendered by default.

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
}
},
},
})]
}

}