Files
tools/vue/editor/src/keymap/compile.ts
T
robonen 09272dffeb feat(editor): eslint/tsconfig migration + type fixes
@robonen/editor: migrate to eslint flat config + composite tsconfig; fix
convergence test type annotations.
2026-06-07 16:30:05 +07:00

23 lines
746 B
TypeScript

import type { Command } from '../state';
import type { Platform } from '../view/config';
import type { Keymap } from './types';
import { normalizeCombo } from './normalize';
/**
* Merge ordered keymaps into a single normalized lookup. Earlier keymaps win, so
* pass user overrides before the defaults: `compileKeymaps([user, defaults], …)`.
*/
export function compileKeymaps(keymaps: readonly Keymap[], platform: Platform): Map<string, Command> {
const compiled = new Map<string, Command>();
for (const keymap of keymaps) {
for (const combo in keymap) {
const normalized = normalizeCombo(combo, platform);
if (!compiled.has(normalized))
compiled.set(normalized, keymap[combo]!);
}
}
return compiled;
}