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

Add Jump-To hotkeys #3483

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions client/homebrew/editor/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const Editor = createClass({
this.updateEditorSize();
this.highlightCustomMarkdown();
window.addEventListener('resize', this.updateEditorSize);
document.getElementById('BrewRenderer').addEventListener('keydown', this.handleControlKeys);
document.addEventListener('keydown', this.handleControlKeys);

const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
if(editorTheme) {
Expand All @@ -71,6 +73,10 @@ const Editor = createClass({

componentDidUpdate : function(prevProps, prevState, snapshot) {
this.highlightCustomMarkdown();
if(this.props.jumpSource) {
this.sourceJump();
this.setState({sourceJump: false});
}
if(prevProps.moveBrew !== this.props.moveBrew) {
this.brewJump();
};
Expand All @@ -79,6 +85,19 @@ const Editor = createClass({
};
},

handleControlKeys : function(e){
if(!(e.ctrlKey || e.metaKey)) return;
console.log(e);
const X_KEY = 88;
if((!e.shiftKey) && (e.keyCode == X_KEY)) this.brewJump();
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
if (e.shiftKey && (e.keyCode == X_KEY)) this.sourceJump();
if( e.keyCode == X_KEY) {
e.stopPropagation();
e.preventDefault();
}
},


updateEditorSize : function() {
if(this.refs.codeEditor) {
let paneHeight = this.refs.main.parentNode.clientHeight;
Expand Down Expand Up @@ -116,6 +135,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();
Expand Down