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

Function registerCommandsFromKeyBindings

src/cm/commandRegistry.js:1208–1253  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1206}
1207
1208function registerCommandsFromKeyBindings() {
1209 Object.entries(keyBindings).forEach(([name, binding]) => {
1210 if (commandMap.has(name)) return;
1211 const description = binding?.description || humanizeCommandName(name);
1212 const readOnly = binding?.readOnly ?? false;
1213 const requiresView = !!binding?.editorOnly;
1214 const commandFn = CODEMIRROR_COMMAND_MAP.get(name);
1215
1216 if (binding?.action) {
1217 addCommand({
1218 name,
1219 description,
1220 readOnly,
1221 requiresView,
1222 run(view) {
1223 try {
1224 if (requiresView) {
1225 const resolvedView = resolveView(view);
1226 if (!resolvedView) return false;
1227 }
1228 acode.exec(binding.action);
1229 return true;
1230 } catch (error) {
1231 console.error(`Failed to execute action ${binding.action}`, error);
1232 return false;
1233 }
1234 },
1235 });
1236 return;
1237 }
1238
1239 if (commandFn) {
1240 addCommand({
1241 name,
1242 description,
1243 readOnly,
1244 requiresView: true,
1245 run(view) {
1246 const resolvedView = resolveView(view);
1247 if (!resolvedView) return false;
1248 return commandFn(resolvedView);
1249 },
1250 });
1251 }
1252 });
1253}
1254
1255function addCommand(entry) {
1256 const command = {

Callers 1

commandRegistry.jsFile · 0.85

Calls 3

humanizeCommandNameFunction · 0.70
addCommandFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected