()
| 326 | // shared with the Quick Note window so both editors behave identically (#312). |
| 327 | |
| 328 | function registerVimCommands(): void { |
| 329 | if (vimCommandsRegistered) return |
| 330 | vimCommandsRegistered = true |
| 331 | |
| 332 | // HMR can leave old custom mappings alive in CodeMirror-Vim's global |
| 333 | // map table. Explicitly remove the temporary `x` close-note binding |
| 334 | // so normal-mode `x` keeps its default delete-char behavior. |
| 335 | try { |
| 336 | Vim.unmap('x', 'normal') |
| 337 | } catch { |
| 338 | /* ignore */ |
| 339 | } |
| 340 | clearKnownVimMappings() |
| 341 | |
| 342 | // Visual-line reorder: select line(s) with Shift+V, then Shift+J / Shift+K |
| 343 | // move the selection down / up — the well-known Vim "move selected lines" |
| 344 | // mapping. Overrides J/K in *visual* mode only; normal-mode join (J) and |
| 345 | // keyword-lookup (K) are left untouched. moveLineDown/Up act on every line |
| 346 | // the selection spans and keep it selected. |
| 347 | Vim.defineAction('zenMoveSelectionDown', (cm: ReturnType<typeof getCM>) => { |
| 348 | const view = (cm as unknown as { cm6?: EditorView }).cm6 |
| 349 | if (view) moveLineDown(view) |
| 350 | }) |
| 351 | Vim.defineAction('zenMoveSelectionUp', (cm: ReturnType<typeof getCM>) => { |
| 352 | const view = (cm as unknown as { cm6?: EditorView }).cm6 |
| 353 | if (view) moveLineUp(view) |
| 354 | }) |
| 355 | Vim.mapCommand('J', 'action', 'zenMoveSelectionDown', {}, { context: 'visual' }) |
| 356 | Vim.mapCommand('K', 'action', 'zenMoveSelectionUp', {}, { context: 'visual' }) |
| 357 | |
| 358 | // #290/#312: make j/k move by display line through soft-wrapped content. |
| 359 | // Shared with the Quick Note window (QuickCaptureApp) via the same helper. |
| 360 | registerDisplayLineMotion() |
| 361 | |
| 362 | Vim.defineEx('write', 'w', () => { |
| 363 | void useStore.getState().persistActive() |
| 364 | }) |
| 365 | Vim.defineEx('format', 'format', () => { |
| 366 | void useStore.getState().formatActiveNote() |
| 367 | }) |
| 368 | Vim.defineEx('quit', 'q', () => { |
| 369 | const state = useStore.getState() |
| 370 | if (isTasksViewActive(state)) { |
| 371 | state.closeTasksView() |
| 372 | return |
| 373 | } |
| 374 | if (isTagsViewActive(state)) { |
| 375 | state.closeTagView() |
| 376 | return |
| 377 | } |
| 378 | void state.closeActiveNote() |
| 379 | }) |
| 380 | Vim.defineEx('wq', 'wq', () => { |
| 381 | const state = useStore.getState() |
| 382 | if (isTasksViewActive(state)) { |
| 383 | state.closeTasksView() |
| 384 | return |
| 385 | } |
no test coverage detected