From 111a2a7135462c79d28c73aef2240edd0247c375 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lopes" Date: Thu, 29 Feb 2024 16:08:12 +0000 Subject: [PATCH] latter command key override --- src/lib/commandCenter/commands.ts | 25 ++++++++++++++++--- src/lib/helpers/omit.ts | 7 ++++++ .../messaging/+layout.svelte | 12 ++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/lib/helpers/omit.ts diff --git a/src/lib/commandCenter/commands.ts b/src/lib/commandCenter/commands.ts index c24491b6d..fffd0be31 100644 --- a/src/lib/commandCenter/commands.ts +++ b/src/lib/commandCenter/commands.ts @@ -5,6 +5,7 @@ import { onMount } from 'svelte'; import { derived, writable } from 'svelte/store'; import { nanoid } from 'nanoid/non-secure'; import { trackEvent } from '$lib/actions/analytics'; +import { omit } from '$lib/helpers/omit'; const groups = [ 'ungrouped', @@ -73,7 +74,23 @@ export const disabledMap = writable>(new Map()); // Derived stores export const commands = derived(commandMap, ($commandMap) => { - return Array.from($commandMap.values()).flat(); + const res: Command[] = []; + const keys = new Set(); + + const allCommands = Array.from($commandMap.values()).flat().toReversed(); + + for (const command of allCommands) { + if (isKeyedCommand(command) && !command.disabled) { + const keysString = command.keys.join('+'); + if (keys.has(keysString)) { + res.push(omit(command, 'keys')); + continue; + } + keys.add(keysString); + } + res.push(command); + } + return res; }); const commandsEnabled = derived(disabledMap, ($disabledMap) => { @@ -113,9 +130,9 @@ function hasDisputing(command: KeyedCommand, allCommands: Command[]) { } export const commandCenterKeyDownHandler = derived( - [commandMap, commandsEnabled, wizard], - ([$commandMap, enabled, $wizard]) => { - const commandsArr = Array.from($commandMap.values()).flat(); + [commands, commandsEnabled, wizard], + ([$commands, enabled, $wizard]) => { + const commandsArr = $commands; let recentKeyCodes: number[] = []; let validCommands: KeyedCommand[] = []; diff --git a/src/lib/helpers/omit.ts b/src/lib/helpers/omit.ts new file mode 100644 index 000000000..e91440738 --- /dev/null +++ b/src/lib/helpers/omit.ts @@ -0,0 +1,7 @@ +export function omit(obj: T, ...keys: K[]): Omit { + const ret = { ...obj }; + for (const key of keys) { + delete ret[key]; + } + return ret; +} diff --git a/src/routes/console/project-[project]/messaging/+layout.svelte b/src/routes/console/project-[project]/messaging/+layout.svelte index 143a1f4a5..b379323a0 100644 --- a/src/routes/console/project-[project]/messaging/+layout.svelte +++ b/src/routes/console/project-[project]/messaging/+layout.svelte @@ -1,7 +1,12 @@