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