* Vim-muscle-memory ex commands for buffer (tab) / file operations. These * sit above the auto-registered palette commands so their short names * (`:e`, `:bn`, `:bd`) are reserved and not overwritten. * * - `:e[dit] ` open a note by vault-relative path, create if missing * - `:new <pa
()
| 650 | * - `:h[elp]` open the built-in Help manual |
| 651 | */ |
| 652 | function registerVimNoteCommands(): void { |
| 653 | const getActiveLeaf = (): { id: string; tabs: string[]; activeTab: string | null } | null => { |
| 654 | const s = useStore.getState() |
| 655 | const leaves = allLeavesFlat(s.paneLayout) |
| 656 | return leaves.find((l) => l.id === s.activePaneId) ?? null |
| 657 | } |
| 658 | |
| 659 | const openOrCreateByPath = async (raw: string): Promise<void> => { |
| 660 | const value = raw.trim() |
| 661 | if (!value) return |
| 662 | let parsed: ReturnType<typeof parseCreateNotePath> |
| 663 | try { |
| 664 | parsed = parseCreateNotePath(value) |
| 665 | } catch (err) { |
| 666 | alertEditorError((err as Error).message) |
| 667 | return |
| 668 | } |
| 669 | const state = useStore.getState() |
| 670 | // If something already resolves to that target (wiki-style + case- |
| 671 | // insensitive), open it instead of creating a duplicate. |
| 672 | const existing = state.notes.find( |
| 673 | (n) => |
| 674 | n.folder !== 'trash' && |
| 675 | n.path.toLowerCase() === parsed.relPath.toLowerCase() |
| 676 | ) |
| 677 | if (existing) { |
| 678 | await state.selectNote(existing.path) |
| 679 | state.setFocusedPanel('editor') |
| 680 | requestAnimationFrame(() => useStore.getState().editorViewRef?.focus()) |
| 681 | return |
| 682 | } |
| 683 | await state.createAndOpen(parsed.folder, parsed.subpath, { |
| 684 | title: parsed.title |
| 685 | }) |
| 686 | state.setFocusedPanel('editor') |
| 687 | requestAnimationFrame(() => useStore.getState().editorViewRef?.focus()) |
| 688 | } |
| 689 | |
| 690 | Vim.defineEx( |
| 691 | 'edit', |
| 692 | 'e', |
| 693 | (_cm: unknown, params: { argString?: string } | undefined) => { |
| 694 | void openOrCreateByPath(params?.argString ?? '') |
| 695 | } |
| 696 | ) |
| 697 | |
| 698 | // `:new` shadows vim's "horizontal split empty buffer" — for a notes |
| 699 | // app, creating a new note at a path is what the user actually wants. |
| 700 | Vim.defineEx( |
| 701 | 'new', |
| 702 | 'new', |
| 703 | (_cm: unknown, params: { argString?: string } | undefined) => { |
| 704 | const arg = (params?.argString ?? '').trim() |
| 705 | if (!arg) { |
| 706 | void useStore.getState().createAndOpen('inbox', '', { focusTitle: true }) |
| 707 | return |
| 708 | } |
| 709 | void openOrCreateByPath(arg) |
no test coverage detected