keyBindings/definition.ts: use macros in strings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
function formatComment(comment: string | undefined) {
|
||||
return comment === undefined ? "" : ` (${comment})`;
|
||||
function formatDescription(item: {description: string, comment?: string}) {
|
||||
const suffix = item.comment === undefined ? "" : ` (${item.comment})`;
|
||||
return `${applyMacro(item.description, "N")}${suffix}`;
|
||||
}
|
||||
|
||||
function printCols(...columns: (string[] | string)[]) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
console.log(`[list]`);
|
||||
|
||||
for (const binding of keyBindings) {
|
||||
console.log(` [*] ${binding.defaultKeySequence} — ${binding.description}${formatComment(binding.comment)}`);
|
||||
console.log(` [*] ${binding.defaultKeySequence} — ${formatDescription(binding)}`);
|
||||
}
|
||||
|
||||
for (const binding of numKeyBindings) {
|
||||
const numPrefix = binding.fKeys ? "F" : "";
|
||||
console.log(` [*] ${binding.defaultModifiers}+${numPrefix}[N] — ${binding.description}N${formatComment(binding.comment)}`);
|
||||
console.log(` [*] ${binding.defaultModifiers}+${numPrefix}[N] — ${formatDescription(binding)}`);
|
||||
}
|
||||
|
||||
console.log(`[/list]`);
|
||||
|
||||
@@ -7,8 +7,8 @@ const colLeft = [
|
||||
];
|
||||
|
||||
const colRight = [
|
||||
...keyBindings.map((binding: KeyBinding) => `${binding.description}${formatComment(binding.comment)}`),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => `${binding.description}N${formatComment(binding.comment)}`),
|
||||
...keyBindings.map(formatDescription),
|
||||
...numKeyBindings.map(formatDescription),
|
||||
];
|
||||
|
||||
printCols(colLeft, " ", colRight);
|
||||
|
||||
@@ -11,8 +11,8 @@ const colLeft = [
|
||||
const colRight = [
|
||||
"Action",
|
||||
"---",
|
||||
...keyBindings.map((binding: KeyBinding) => `${binding.description}${formatComment(binding.comment)}`),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => `${binding.description}N${formatComment(binding.comment)}`),
|
||||
...keyBindings.map((binding: KeyBinding) => `${formatDescription(binding)}`),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => `${formatDescription(binding)}`),
|
||||
];
|
||||
|
||||
printCols("| ", colLeft, " | ", colRight, " |");
|
||||
|
||||
@@ -187,39 +187,39 @@ function getKeyBindings(world: World, actions: Actions): KeyBinding[] {
|
||||
function getNumKeyBindings(world: World, actions: Actions): NumKeyBinding[] {
|
||||
return [
|
||||
{
|
||||
name: "focus-",
|
||||
description: "Move focus to column ",
|
||||
name: "focus-{}",
|
||||
description: "Move focus to column {}",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultModifiers: "Meta",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.do(actions.focus.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "window-move-to-column-",
|
||||
description: "Move window to column ",
|
||||
name: "window-move-to-column-{}",
|
||||
description: "Move window to column {}",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!",
|
||||
defaultModifiers: "Meta+Shift",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.windowMoveToColumn.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "column-move-to-column-",
|
||||
description: "Move column to position ",
|
||||
name: "column-move-to-column-{}",
|
||||
description: "Move column to position {}",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.columnMoveToColumn.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "column-move-to-desktop-",
|
||||
description: "Move column to desktop ",
|
||||
name: "column-move-to-desktop-{}",
|
||||
description: "Move column to desktop {}",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: true,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.columnMoveToDesktop.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "tail-move-to-desktop-",
|
||||
description: "Move this and all following columns to desktop ",
|
||||
name: "tail-move-to-desktop-{}",
|
||||
description: "Move this and all following columns to desktop {}",
|
||||
defaultModifiers: "Meta+Ctrl+Shift+Alt",
|
||||
fKeys: true,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.tailMoveToDesktop.partial(i)),
|
||||
|
||||
@@ -43,8 +43,8 @@ function registerNumKeyBindings(shortcutActions: ShortcutAction[], numKeyBinding
|
||||
"";
|
||||
shortcutActions.push(new ShortcutAction(
|
||||
{
|
||||
name: numKeyBinding.name + numKey,
|
||||
description: numKeyBinding.description + numKey,
|
||||
name: applyMacro(numKeyBinding.name, numKey),
|
||||
description: applyMacro(numKeyBinding.description, numKey),
|
||||
defaultKeySequence: keySequence,
|
||||
},
|
||||
catchWrap(() => numKeyBinding.action(i)),
|
||||
|
||||
3
src/lib/utils/strings.ts
Normal file
3
src/lib/utils/strings.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
function applyMacro(base: string, value: string) {
|
||||
return base.replace("{}", String(value));
|
||||
}
|
||||
Reference in New Issue
Block a user