From 6a11e1d0d8ae40ae2e910d51d50420d599b83dac Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Tue, 25 Oct 2022 04:43:35 +0800 Subject: [PATCH] refactor key bindings --- src/editor/calltree.js | 4 ++++ src/editor/editor.js | 34 ++++------------------------------ src/editor/logs.js | 4 ++++ src/editor/ui.js | 33 +++++++++++---------------------- src/editor/value_explorer.js | 5 +++++ 5 files changed, 28 insertions(+), 52 deletions(-) diff --git a/src/editor/calltree.js b/src/editor/calltree.js index 3b414f5..6c0b7cf 100644 --- a/src/editor/calltree.js +++ b/src/editor/calltree.js @@ -23,6 +23,10 @@ export class CallTree { // Do not scroll e.preventDefault() + if(e.key == 'Escape') { + this.ui.editor.focus() + } + if(e.key == 'F1') { this.ui.editor.focus_value_explorer(this.container) } diff --git a/src/editor/editor.js b/src/editor/editor.js index ea6a841..37dcf76 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -291,28 +291,10 @@ export class Editor { const VimApi = require("ace/keyboard/vim").CodeMirror.Vim - - this.ace_editor.commands.bindKey("F2", "switch_window"); - VimApi._mapCommand({ - keys: '', - type: 'action', - action: 'aceCommand', - actionArgs: { name: "switch_window" } - }) - this.ace_editor.commands.addCommand({ - name: 'switch_window', - exec: (editor) => { - this.ui.set_active_tab('calltree') - } - }) - - this.ace_editor.commands.bindKey("F3", "focus_logs"); - this.ace_editor.commands.addCommand({ - name: 'focus_logs', - exec: (editor) => { - this.ui.set_active_tab('logs') - } - }) + // Remove commands binded to function keys that we are going to redefine + this.ace_editor.commands.removeCommand('openCommandPallete') + this.ace_editor.commands.removeCommand('toggleFoldWidget') + this.ace_editor.commands.removeCommand('goToNextError') this.ace_editor.commands.bindKey("F4", "goto_definition"); @@ -329,14 +311,6 @@ export class Editor { } }) - this.ace_editor.commands.bindKey("F5", "fullscreen_editor"); - this.ace_editor.commands.addCommand({ - name: 'fullscreen_editor', - exec: (editor) => { - this.ui.fullscreen_editor() - } - }) - this.ace_editor.commands.bindKey("F1", "focus_value_explorer"); this.ace_editor.commands.addCommand({ diff --git a/src/editor/logs.js b/src/editor/logs.js index 4558818..7d4ddf6 100644 --- a/src/editor/logs.js +++ b/src/editor/logs.js @@ -8,6 +8,10 @@ export class Logs { this.ui = ui this.el.addEventListener('keydown', (e) => { + if(e.key == 'Escape') { + this.ui.editor.focus() + } + if(e.key == 'Enter') { // TODO reselect call node that was selected previously by calling // 'calltree.navigate_logs_position' diff --git a/src/editor/ui.js b/src/editor/ui.js index 666e7a3..80255d7 100644 --- a/src/editor/ui.js +++ b/src/editor/ui.js @@ -114,34 +114,19 @@ export class UI { this.root.addEventListener('keydown', () => this.clear_status(), true) this.root.addEventListener('click', () => this.clear_status(), true) - this.editor_container.addEventListener('keydown', e => { - // Bind F2 and F3 for embed_value_explorer - if( - e.key.toLowerCase() == 'w' && e.ctrlKey == true - || - e.key == 'F2' - ){ + this.root.addEventListener('keydown', e => { + if(e.key == 'F2') { this.set_active_tab('calltree') } if(e.key == 'F3'){ this.set_active_tab('logs') } - }) - const escape = e => { - if( - (e.key.toLowerCase() == 'w' && e.ctrlKey == true) - || - e.key == 'Escape' - ){ - this.editor.focus() + if(e.key == 'F5'){ + this.fullscreen_editor() } - } - - this.debugger.calltree.addEventListener('keydown', escape) - this.debugger.logs.addEventListener('keydown', escape) - + }) if(!FLAGS.embed_value_explorer) { this.eval = new Eval(this, this.eval_container) @@ -270,12 +255,13 @@ export class UI { const options = [ ['Focus value explorer', 'F1'], ['Navigate value explorer', '← → ↑ ↓ or hjkl'], - ['Leave value explorer', 'Esc'], - ['Switch between editor and call tree view', 'F2 or Ctrl-w'], + ['Leave value explorer', 'F1 or Esc'], + ['Focus call tree view', 'F2'], ['Navigate call tree view', '← → ↑ ↓ or hjkl'], ['Leave call tree view', 'F2 or Esc'], ['Focus console logs', 'F3'], ['Navigate console logs', '↑ ↓ or jk'], + ['Leave console logs', 'F3 or Esc'], ['Jump to definition', 'F4', 'gd'], ['Expand selection to eval expression', 'Ctrl-↓ or Ctrl-j'], ['Collapse selection', 'Ctrl-↑ or Ctrl-k'], @@ -318,6 +304,9 @@ export class UI { fullscreen_editor() { this.root.classList.toggle('fullscreen_editor') this.editor.ace_editor.resize() + if(this.root.classList.contains('fullscreen_editor')) { + this.editor.focus() + } } } diff --git a/src/editor/value_explorer.js b/src/editor/value_explorer.js index 8b999f1..020a6c3 100644 --- a/src/editor/value_explorer.js +++ b/src/editor/value_explorer.js @@ -129,6 +129,11 @@ export class ValueExplorer { Click - select and toggles expand */ + + if(e.key == 'F1') { + this.on_escape() + return + } const current_object = get_path(this.value, this.current_path)