mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Add new keymaps to jump between tabs (#2330)
This commit is contained in:
parent
2b61d4c081
commit
bcf1157b37
7 changed files with 54 additions and 3 deletions
|
|
@ -5,10 +5,25 @@ const {defaultPlatformKeyPath} = require('./paths');
|
|||
const commands = {};
|
||||
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) {
|
||||
for (const command in keymap) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"tab:new": "cmd+t",
|
||||
"tab:next": "cmd+shift+]",
|
||||
"tab:prev": "cmd+shift+[",
|
||||
"tab:jump:prefix": "cmd",
|
||||
"pane:next": "cmd+]",
|
||||
"pane:prev": "cmd+[",
|
||||
"pane:splitVertical": "cmd+d",
|
||||
|
|
@ -28,4 +29,4 @@
|
|||
"editor:clearBuffer": "cmd+k",
|
||||
"editor:emojis": "cmd+ctrl+space",
|
||||
"plugins:update": "cmd+shift+u"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"tab:new": "ctrl+shift+t",
|
||||
"tab:next": "ctrl+tab",
|
||||
"tab:prev": "ctrl+shift+tab",
|
||||
"tab:jump:prefix": "ctrl",
|
||||
"pane:next": "ctrl+pageup",
|
||||
"pane:prev": "ctrl+pagedown",
|
||||
"pane:splitVertical": "ctrl+shift+d",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"tab:new": "ctrl+shift+t",
|
||||
"tab:next": "ctrl+tab",
|
||||
"tab:prev": "ctrl+shift+tab",
|
||||
"tab:jump:prefix": "ctrl",
|
||||
"pane:next": "ctrl+pageup",
|
||||
"pane:prev": "ctrl+pagedown",
|
||||
"pane:splitVertical": "ctrl+shift+d",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,21 @@
|
|||
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 {
|
||||
role: 'window',
|
||||
submenu: [
|
||||
|
|
@ -34,7 +51,11 @@ module.exports = commands => {
|
|||
focusedWindow.rpc.emit('move right req');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
...tabJump
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -180,6 +180,14 @@ export function moveRight() {
|
|||
|
||||
export function moveTo(i) {
|
||||
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({
|
||||
type: UI_MOVE_TO,
|
||||
index: i,
|
||||
|
|
|
|||
|
|
@ -99,6 +99,10 @@ rpc.on('move right req', () => {
|
|||
store_.dispatch(uiActions.moveRight());
|
||||
});
|
||||
|
||||
rpc.on('move jump req', index => {
|
||||
store_.dispatch(uiActions.moveTo(index));
|
||||
});
|
||||
|
||||
rpc.on('next pane req', () => {
|
||||
store_.dispatch(uiActions.moveToNextPane());
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue