From 9b0db1508349407de77f97f64874b0971ca24e0b Mon Sep 17 00:00:00 2001 From: David Bolack Date: Fri, 17 May 2024 22:10:28 -0500 Subject: [PATCH] Add Jump To hotkeys This binds CTRL/META-J to brewJump and SHIFT-CTRL/META-J to sourceJump. --- client/homebrew/editor/editor.jsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index f5c1766a8..119658f8c 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -56,6 +56,7 @@ const Editor = createClass({ this.updateEditorSize(); this.highlightCustomMarkdown(); window.addEventListener('resize', this.updateEditorSize); + document.addEventListener('keydown', this.handleControlKeys); const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY); if(editorTheme) { @@ -79,6 +80,18 @@ const Editor = createClass({ }; }, + handleControlKeys : function(e){ + if(!(e.ctrlKey || e.metaKey)) return; + const J_KEY = 74; + if((!e.shiftKey) && (e.keyCode == J_KEY)) this.brewJump(); + if (e.shiftKey && (e.keyCode == J_KEY)) this.sourceJump(); + if( e.keyCode == J_KEY) { + e.stopPropagation(); + e.preventDefault(); + } + }, + + updateEditorSize : function() { if(this.refs.codeEditor) { let paneHeight = this.refs.main.parentNode.clientHeight; @@ -116,6 +129,7 @@ const Editor = createClass({ const codeMirror = this.refs.codeEditor.codeMirror; codeMirror.operation(()=>{ // Batch CodeMirror styling + //reset custom text styles const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();