Add new keymaps to jump between tabs (#2330)

This commit is contained in:
CHaBou 2017-10-05 20:39:39 +02:00 committed by GitHub
parent 2b61d4c081
commit bcf1157b37
7 changed files with 54 additions and 3 deletions

View file

@ -5,10 +5,25 @@ const {defaultPlatformKeyPath} = require('./paths');
const commands = {}; const commands = {};
const keys = {}; const keys = {};
const generatePrefixedCommand = function(command, key) {
const baseCmd = command.replace(/:prefix$/, '');
for (let i = 1; i <= 9; i++) {
// 9 is a special number because it means 'last'
const index = i === 9 ? 'last' : i;
commands[`${baseCmd}:${index}`] = normalize(`${key}+${i}`);
}
};
const _setKeysForCommands = function(keymap) { const _setKeysForCommands = function(keymap) {
for (const command in keymap) { for (const command in keymap) {
if (command) { if (command) {
commands[command] = normalize(keymap[command]); // In case of a command finishing by :prefix
// we need to generate commands and keys
if (command.endsWith(':prefix')) {
generatePrefixedCommand(command, keymap[command]);
} else {
commands[command] = normalize(keymap[command]);
}
} }
} }
}; };

View file

@ -14,6 +14,7 @@
"tab:new": "cmd+t", "tab:new": "cmd+t",
"tab:next": "cmd+shift+]", "tab:next": "cmd+shift+]",
"tab:prev": "cmd+shift+[", "tab:prev": "cmd+shift+[",
"tab:jump:prefix": "cmd",
"pane:next": "cmd+]", "pane:next": "cmd+]",
"pane:prev": "cmd+[", "pane:prev": "cmd+[",
"pane:splitVertical": "cmd+d", "pane:splitVertical": "cmd+d",
@ -28,4 +29,4 @@
"editor:clearBuffer": "cmd+k", "editor:clearBuffer": "cmd+k",
"editor:emojis": "cmd+ctrl+space", "editor:emojis": "cmd+ctrl+space",
"plugins:update": "cmd+shift+u" "plugins:update": "cmd+shift+u"
} }

View file

@ -14,6 +14,7 @@
"tab:new": "ctrl+shift+t", "tab:new": "ctrl+shift+t",
"tab:next": "ctrl+tab", "tab:next": "ctrl+tab",
"tab:prev": "ctrl+shift+tab", "tab:prev": "ctrl+shift+tab",
"tab:jump:prefix": "ctrl",
"pane:next": "ctrl+pageup", "pane:next": "ctrl+pageup",
"pane:prev": "ctrl+pagedown", "pane:prev": "ctrl+pagedown",
"pane:splitVertical": "ctrl+shift+d", "pane:splitVertical": "ctrl+shift+d",

View file

@ -14,6 +14,7 @@
"tab:new": "ctrl+shift+t", "tab:new": "ctrl+shift+t",
"tab:next": "ctrl+tab", "tab:next": "ctrl+tab",
"tab:prev": "ctrl+shift+tab", "tab:prev": "ctrl+shift+tab",
"tab:jump:prefix": "ctrl",
"pane:next": "ctrl+pageup", "pane:next": "ctrl+pageup",
"pane:prev": "ctrl+pagedown", "pane:prev": "ctrl+pagedown",
"pane:splitVertical": "ctrl+shift+d", "pane:splitVertical": "ctrl+shift+d",

View file

@ -1,4 +1,21 @@
module.exports = commands => { module.exports = commands => {
// Generating tab:jump array
const tabJump = [];
for (let i = 1; i <= 9; i++) {
// 9 is a special number because it means 'last'
const label = i === 9 ? 'Last' : `${i}`;
const tabIndex = i === 9 ? 'last' : i - 1;
tabJump.push({
label: label,
accelerator: commands[`tab:jump:${label.toLowerCase()}`],
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('move jump req', tabIndex);
}
}
});
}
return { return {
role: 'window', role: 'window',
submenu: [ submenu: [
@ -34,7 +51,11 @@ module.exports = commands => {
focusedWindow.rpc.emit('move right req'); focusedWindow.rpc.emit('move right req');
} }
} }
} },
{
type: 'separator'
},
...tabJump
] ]
}, },
{ {

View file

@ -180,6 +180,14 @@ export function moveRight() {
export function moveTo(i) { export function moveTo(i) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (i === 'last') {
// Finding last tab index
const {termGroups} = getState().termGroups;
i =
Object.keys(termGroups)
.map(uid => termGroups[uid])
.filter(({parentUid}) => !parentUid).length - 1;
}
dispatch({ dispatch({
type: UI_MOVE_TO, type: UI_MOVE_TO,
index: i, index: i,

View file

@ -99,6 +99,10 @@ rpc.on('move right req', () => {
store_.dispatch(uiActions.moveRight()); store_.dispatch(uiActions.moveRight());
}); });
rpc.on('move jump req', index => {
store_.dispatch(uiActions.moveTo(index));
});
rpc.on('next pane req', () => { rpc.on('next pane req', () => {
store_.dispatch(uiActions.moveToNextPane()); store_.dispatch(uiActions.moveToNextPane());
}); });