()
| 1206 | } |
| 1207 | |
| 1208 | function 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 | |
| 1255 | function addCommand(entry) { |
| 1256 | const command = { |
no test coverage detected