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 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CTRL + x is "cut". We definitely don't want to overwrite that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a suggestion:
CTRL + ALT + RIGHT => move brew preview to match editor position
CTRL+ ALT + LEFT => move editor to match brew preview position

I don't believe these combinations currently have any existing use, please let me know if I'm mistaken

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