split keyBindings and numKeyBindings
This commit is contained in:
@@ -251,7 +251,11 @@ function initActions(world: World) {
|
||||
grid.scrollToColumn(nextColumn);
|
||||
grid.arrange();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function initNumActions(world: World) {
|
||||
return {
|
||||
focusColumn: (columnIndex: number) => {
|
||||
const grid = world.getCurrentGrid();
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
|
||||
@@ -3,7 +3,14 @@ interface KeyBinding {
|
||||
description: string;
|
||||
defaultKeySequence: string;
|
||||
action: keyof ReturnType<typeof initActions>;
|
||||
repeat?: number;
|
||||
}
|
||||
|
||||
interface NumKeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
action: keyof ReturnType<typeof initNumActions>;
|
||||
}
|
||||
|
||||
const keyBindings: KeyBinding[] = [
|
||||
@@ -175,40 +182,42 @@ const keyBindings: KeyBinding[] = [
|
||||
"defaultKeySequence": "Meta+Alt+End",
|
||||
"action": "gridScrollEnd",
|
||||
},
|
||||
];
|
||||
|
||||
const numKeyBindings: NumKeyBinding[] = [
|
||||
{
|
||||
"name": "focus-",
|
||||
"description": "Move focus to column ",
|
||||
"defaultKeySequence": "Meta+",
|
||||
"defaultModifiers": "Meta",
|
||||
"fKeys": false,
|
||||
"action": "focusColumn",
|
||||
"repeat": 9
|
||||
},
|
||||
{
|
||||
"name": "window-move-to-column-",
|
||||
"description": "Move window to column ",
|
||||
"defaultKeySequence": "Meta+Shift+",
|
||||
"defaultModifiers": "Meta+Shift",
|
||||
"fKeys": false,
|
||||
"action": "windowMoveToColumn",
|
||||
"repeat": 9
|
||||
},
|
||||
{
|
||||
"name": "column-move-to-column-",
|
||||
"description": "Move column to position ",
|
||||
"defaultKeySequence": "Meta+Ctrl+Shift+",
|
||||
"defaultModifiers": "Meta+Ctrl+Shift",
|
||||
"fKeys": false,
|
||||
"action": "columnMoveToColumn",
|
||||
"repeat": 9
|
||||
},
|
||||
{
|
||||
"name": "column-move-to-desktop-",
|
||||
"description": "Move column to desktop ",
|
||||
"defaultKeySequence": "Meta+Ctrl+Shift+F",
|
||||
"defaultModifiers": "Meta+Ctrl+Shift",
|
||||
"fKeys": true,
|
||||
"action": "columnMoveToDesktop",
|
||||
"repeat": 12
|
||||
},
|
||||
{
|
||||
"name": "tail-move-to-desktop-",
|
||||
"description": "Move this and all following columns to desktop ",
|
||||
"defaultKeySequence": "Meta+Ctrl+Shift+Alt+F",
|
||||
"defaultModifiers": "Meta+Ctrl+Shift+Alt",
|
||||
"fKeys": true,
|
||||
"action": "tailMoveToDesktop",
|
||||
"repeat": 12
|
||||
},
|
||||
];
|
||||
|
||||
@@ -18,13 +18,15 @@ function registerKeyBinding(name: string, description: string, keySequence: stri
|
||||
);
|
||||
}
|
||||
|
||||
function registerNumKeyBindings(name: string, description: string, keySequence: string, callback: (i: number) => void, n: number) {
|
||||
function registerNumKeyBindings(name: string, description: string, modifiers: string, fKeys: boolean, callback: (i: number) => void) {
|
||||
const numPrefix = fKeys ? "F" : "";
|
||||
const n = fKeys ? 12 : 9;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const numKey = String(i + 1);
|
||||
registerKeyBinding(
|
||||
name + numKey,
|
||||
description + numKey,
|
||||
keySequence + numKey,
|
||||
modifiers + "+" + numPrefix + numKey,
|
||||
() => callback(i),
|
||||
);
|
||||
}
|
||||
@@ -33,12 +35,11 @@ function registerNumKeyBindings(name: string, description: string, keySequence:
|
||||
function registerKeyBindings(world: World) {
|
||||
const actions = initActions(world);
|
||||
for (const binding of keyBindings) {
|
||||
if (binding.repeat === undefined) {
|
||||
const action = <() => void> actions[binding.action];
|
||||
registerKeyBinding(binding.name, binding.description, binding.defaultKeySequence, action);
|
||||
} else {
|
||||
const action = <(n: number) => void> actions[binding.action];
|
||||
registerNumKeyBindings(binding.name, binding.description, binding.defaultKeySequence, action, binding.repeat);
|
||||
}
|
||||
registerKeyBinding(binding.name, binding.description, binding.defaultKeySequence, actions[binding.action]);
|
||||
}
|
||||
|
||||
const numActions = initNumActions(world);
|
||||
for (const binding of numKeyBindings) {
|
||||
registerNumKeyBindings(binding.name, binding.description, binding.defaultModifiers, binding.fKeys, numActions[binding.action]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user