From f8f6dbfe0dd701d8f6493e29bea2e3aae7d01288 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 5 Apr 2019 15:44:36 +0200 Subject: [PATCH 1/2] switch tab shortkey --- src/app/editor/editor.js | 18 ++++++++++++++++++ src/app/panels/editor-panel.js | 2 ++ src/app/panels/tab-proxy.js | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index 2750ecdd40..2e228e955d 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -130,6 +130,24 @@ class Editor { readOnly: true }) + this.editor.commands.addCommand({ + name: 'movenexttab', + bindKey: {win: 'Ctrl-Right', mac: 'Command-Right'}, + exec: (editor) => { + this.event.trigger('switchNextTab', []) + }, + readOnly: true + }) + + this.editor.commands.addCommand({ + name: 'moveprevioustab', + bindKey: {win: 'Ctrl-Left', mac: 'Command-Left'}, + exec: (editor) => { + this.event.trigger('switchPreviousTab', []) + }, + readOnly: true + }) + this.editor.setShowPrintMargin(false) this.editor.resize(true) diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index 206ef8ab80..b5a474b94c 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -56,6 +56,8 @@ class EditorPanel { self._components.contextView.hide() self._view.mainPanel.style.display = 'block' } + self._components.editor.event.register('switchNextTab', () => { self.tabProxy.switchNextTab() }) + self._components.editor.event.register('switchPreviousTab', () => { self.tabProxy.switchPreviousTab() }) self.appManager.event.on('ensureActivated', (name) => { if (name === 'home') { showApp(name) } }) /* We listen here on event from the tab component to display / hide the editor and mainpanel diff --git a/src/app/panels/tab-proxy.js b/src/app/panels/tab-proxy.js index 23b6f76167..dc731092e3 100644 --- a/src/app/panels/tab-proxy.js +++ b/src/app/panels/tab-proxy.js @@ -10,7 +10,6 @@ export class TabProxy { this.fileManager = fileManager this.appManager = appManager this.editor = editor - this.entities = {} this.data = {} this._view = {} this._handlers = {} @@ -61,6 +60,7 @@ export class TabProxy { this.appManager.deactivateOne(name) } ) + this.switchTab(name) } }) @@ -69,6 +69,37 @@ export class TabProxy { }) } + switchTab (tabName) { + if (this._handlers[tabName]) { + this._handlers[tabName].switchTo() + this._view.filetabs.activateTab(tabName) + } + } + + switchNextTab () { + const active = this._view.filetabs.active + if (active && this._handlers[active]) { + const handlers = Object.keys(this._handlers) + let i = handlers.indexOf(active) + if (i >= 0) { + i = handlers[i + 1] ? i + 1 : 0 + this.switchTab(handlers[i]) + } + } + } + + switchPreviousTab () { + const active = this._view.filetabs.active + if (active && this._handlers[active]) { + const handlers = Object.keys(this._handlers) + let i = handlers.indexOf(active) + if (i >= 0) { + i = handlers[i - 1] ? i - 1 : handlers.length - 1 + this.switchTab(handlers[i]) + } + } + } + addTab (name, switchTo, close, kind) { var slash = name.split('/') let title = name.indexOf('/') !== -1 ? slash[slash.length - 1] : name From e59e9ed25aba39c4cee3f1432e86fc0df1410a21 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 8 Apr 2019 13:08:07 +0200 Subject: [PATCH 2/2] use alt-t for switching tab --- src/app/editor/editor.js | 18 ------------------ src/app/panels/editor-panel.js | 7 +++++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index 2e228e955d..2750ecdd40 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -130,24 +130,6 @@ class Editor { readOnly: true }) - this.editor.commands.addCommand({ - name: 'movenexttab', - bindKey: {win: 'Ctrl-Right', mac: 'Command-Right'}, - exec: (editor) => { - this.event.trigger('switchNextTab', []) - }, - readOnly: true - }) - - this.editor.commands.addCommand({ - name: 'moveprevioustab', - bindKey: {win: 'Ctrl-Left', mac: 'Command-Left'}, - exec: (editor) => { - this.event.trigger('switchPreviousTab', []) - }, - readOnly: true - }) - this.editor.setShowPrintMargin(false) this.editor.resize(true) diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index b5a474b94c..fd0a50f15d 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -56,8 +56,6 @@ class EditorPanel { self._components.contextView.hide() self._view.mainPanel.style.display = 'block' } - self._components.editor.event.register('switchNextTab', () => { self.tabProxy.switchNextTab() }) - self._components.editor.event.register('switchPreviousTab', () => { self.tabProxy.switchPreviousTab() }) self.appManager.event.on('ensureActivated', (name) => { if (name === 'home') { showApp(name) } }) /* We listen here on event from the tab component to display / hide the editor and mainpanel @@ -192,6 +190,11 @@ class EditorPanel { ` // INIT self._adjustLayout('top', self.data._layout.top.offset) + + document.addEventListener('keydown', (e) => { + if (e.altKey && e.keyCode === 84) self.tabProxy.switchNextTab() + }) + return self._view.el } registerCommand (name, command, opts) {