()
| 224 | export const builtinHotkey = (ctx: IPublicModelPluginContext) => { |
| 225 | return { |
| 226 | init() { |
| 227 | const { hotkey, project, logger, canvas } = ctx; |
| 228 | const { clipboard } = canvas; |
| 229 | // hotkey binding |
| 230 | hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => { |
| 231 | logger.info(`action ${action} is triggered`); |
| 232 | |
| 233 | if (canvas.isInLiveEditing) { |
| 234 | return; |
| 235 | } |
| 236 | // TODO: use focus-tracker |
| 237 | const doc = project.currentDocument; |
| 238 | if (isFormEvent(e) || !doc) { |
| 239 | return; |
| 240 | } |
| 241 | e.preventDefault(); |
| 242 | |
| 243 | const sel = doc.selection; |
| 244 | const topItems = sel.getTopNodes(); |
| 245 | // TODO: check can remove |
| 246 | topItems.forEach((node) => { |
| 247 | if (node?.canPerformAction('remove')) { |
| 248 | node && doc.removeNode(node); |
| 249 | } |
| 250 | }); |
| 251 | sel.clear(); |
| 252 | }); |
| 253 | |
| 254 | hotkey.bind('escape', (e: KeyboardEvent, action) => { |
| 255 | logger.info(`action ${action} is triggered`); |
| 256 | |
| 257 | if (canvas.isInLiveEditing) { |
| 258 | return; |
| 259 | } |
| 260 | const sel = project.currentDocument?.selection; |
| 261 | if (isFormEvent(e) || !sel) { |
| 262 | return; |
| 263 | } |
| 264 | e.preventDefault(); |
| 265 | |
| 266 | sel.clear(); |
| 267 | // currentFocus.esc(); |
| 268 | }); |
| 269 | |
| 270 | // command + c copy command + x cut |
| 271 | hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => { |
| 272 | logger.info(`action ${action} is triggered`); |
| 273 | if (canvas.isInLiveEditing) { |
| 274 | return; |
| 275 | } |
| 276 | const doc = project.currentDocument; |
| 277 | if (isFormEvent(e) || !doc) { |
| 278 | return; |
| 279 | } |
| 280 | const anchorValue = document.getSelection()?.anchorNode?.nodeValue; |
| 281 | if (anchorValue && typeof anchorValue === 'string') { |
| 282 | return; |
| 283 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…