MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / buildCodemirrorKeyBindings

Function buildCodemirrorKeyBindings

src/lib/keyBindings.js:611–669  ·  view source on GitHub ↗
(appBindings)

Source from the content-addressed store, hash-verified

609}
610
611function buildCodemirrorKeyBindings(appBindings) {
612 const commandEntries = Object.entries(cmCommands).filter(
613 ([, value]) => typeof value === "function",
614 );
615 const commandNameByFunction = new Map(
616 commandEntries.map(([name, fn]) => [fn, name]),
617 );
618 const comboMap = new Map();
619
620 for (const binding of KEYMAP_SOURCES) {
621 const baseCombos = new Set();
622
623 pushCommandCombo(binding.run, binding.key, "win", baseCombos);
624 pushCommandCombo(binding.run, binding.win, "win", baseCombos);
625 pushCommandCombo(binding.run, binding.linux, "win", baseCombos);
626 pushCommandCombo(binding.run, binding.mac, "mac", baseCombos);
627
628 if (binding.shift) {
629 const shiftName = commandNameByFunction.get(binding.shift);
630 if (shiftName && !appBindings[shiftName]) {
631 const combos = baseCombos.size
632 ? Array.from(baseCombos)
633 : [
634 normalizeKey(binding.key, "win"),
635 normalizeKey(binding.win, "win"),
636 normalizeKey(binding.linux, "win"),
637 normalizeKey(binding.mac, "mac"),
638 ].filter(Boolean);
639 for (const combo of combos) {
640 addCommandCombo(comboMap, shiftName, ensureModifier(combo, "Shift"));
641 }
642 }
643 }
644 }
645
646 const result = {};
647 for (const [name, combos] of comboMap.entries()) {
648 if (!combos.size || appBindings[name]) continue;
649 result[name] = {
650 description: humanizeCommandName(name),
651 key: Array.from(combos)
652 .sort((a, b) => a.localeCompare(b))
653 .join("|"),
654 readOnly: inferReadOnly(name),
655 editorOnly: true,
656 };
657 }
658 return result;
659
660 function pushCommandCombo(commandFn, key, platform, baseCombos) {
661 if (!commandFn) return;
662 const name = commandNameByFunction.get(commandFn);
663 if (!name || appBindings[name]) return;
664 const normalized = normalizeKey(key, platform);
665 if (!normalized) return;
666 addCommandCombo(comboMap, name, normalized);
667 baseCombos.add(normalized);
668 }

Callers 1

keyBindings.jsFile · 0.85

Calls 7

pushCommandComboFunction · 0.85
normalizeKeyFunction · 0.85
addCommandComboFunction · 0.85
ensureModifierFunction · 0.85
inferReadOnlyFunction · 0.85
humanizeCommandNameFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected