Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit 099a9d6

Browse files
committed
✨ Better keyboard shortcut for tabs
1 parent 08f2366 commit 099a9d6

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/_boot.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ app.on('ready', () => {
163163
};
164164
tty.ondisconnected = () => {
165165
signale.error("Lost connection to frontend");
166-
Object.keys(extraTtys).forEach(key => {
167-
if (extraTtys[key] !== null) {
168-
extraTtys[key].close();
169-
extraTtys[key] = null;
170-
}
171-
});
172166
signale.watch("Waiting for frontend connection...");
173167
};
174168

@@ -232,6 +226,7 @@ app.on('ready', () => {
232226
term.ondisconnected = () => {
233227
term.onclosed = () => {};
234228
term.close();
229+
term.wss.close();
235230
extraTtys[term.port] = null;
236231
delete term;
237232
};

src/_renderer.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ window.focusShellTab = (number) => {
427427
};
428428

429429
window.term[number].onprocesschange = p => {
430-
document.getElementById("shell_tab"+number).innerText = `#${number} - ${p}`;
430+
document.getElementById("shell_tab"+number).innerText = `#${number+1} - ${p}`;
431431
};
432432

433433
document.getElementById("shell_tab"+number).innerText = "::"+port;
@@ -441,13 +441,54 @@ window.focusShellTab = (number) => {
441441

442442
// Global keyboard shortcuts
443443
const globalShortcut = electron.remote.globalShortcut;
444+
globalShortcut.unregisterAll();
445+
446+
// Switch tabs
447+
// Next
444448
globalShortcut.register("CommandOrControl+Tab", () => {
445-
if (window.currentTerm <= 3) {
449+
console.log("next");
450+
if (window.term[window.currentTerm+1]) {
446451
window.focusShellTab(window.currentTerm+1);
452+
} else if (window.term[window.currentTerm+2]) {
453+
window.focusShellTab(window.currentTerm+2);
454+
} else if (window.term[window.currentTerm+3]) {
455+
window.focusShellTab(window.currentTerm+3);
456+
} else if (window.term[window.currentTerm+4]) {
457+
window.focusShellTab(window.currentTerm+4);
447458
} else {
448459
window.focusShellTab(0);
449460
}
450461
});
462+
// Previous
463+
globalShortcut.register("CommandOrControl+Shift+Tab", () => {
464+
if (window.term[window.currentTerm-1]) {
465+
window.focusShellTab(window.currentTerm-1);
466+
} else if (window.term[window.currentTerm-2]) {
467+
window.focusShellTab(window.currentTerm-2);
468+
} else if (window.term[window.currentTerm-3]) {
469+
window.focusShellTab(window.currentTerm-3);
470+
} else if (window.term[window.currentTerm-4]) {
471+
window.focusShellTab(window.currentTerm-4);
472+
} else if (window.term[4]){
473+
window.focusShellTab(4);
474+
}
475+
});
476+
// By tab number
477+
globalShortcut.register("CommandOrControl+1", () => {
478+
window.focusShellTab(0);
479+
});
480+
globalShortcut.register("CommandOrControl+2", () => {
481+
window.focusShellTab(1);
482+
});
483+
globalShortcut.register("CommandOrControl+3", () => {
484+
window.focusShellTab(2);
485+
});
486+
globalShortcut.register("CommandOrControl+4", () => {
487+
window.focusShellTab(3);
488+
});
489+
globalShortcut.register("CommandOrControl+5", () => {
490+
window.focusShellTab(4);
491+
});
451492

452493

453494
// Prevent showing menu, exiting fullscreen or app with keyboard shortcuts

0 commit comments

Comments
 (0)