diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index 4780d4b1..73b3254c 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -197,6 +197,27 @@ function BlockNoteTab({ content, entries, onNavigateWikilink }: { content: strin return () => container.removeEventListener('click', handler as EventListener, true) }, [editor]) + // Track active block for highlight — called via onSelectionChange on BlockNoteView + const handleSelectionChange = useCallback(() => { + const container = document.querySelector('.editor__blocknote-container') + if (!container) return + + // Clear previous active + container.querySelectorAll('[data-is-active]').forEach(el => { + el.removeAttribute('data-is-active') + }) + + // Use BlockNote's API to get the current block + const currentBlock = editor.getTextCursorPosition()?.block + if (currentBlock) { + // Find the DOM element for this block by its id + const blockEl = container.querySelector(`[data-id="${currentBlock.id}"].bn-block-outer`) + if (blockEl) { + blockEl.setAttribute('data-is-active', 'true') + } + } + }, [editor]) + // Suggestion menu items for [[ trigger const getWikilinkItems = useCallback(async (query: string) => { const items = entries.map(entry => ({ @@ -223,6 +244,7 @@ function BlockNoteTab({ content, entries, onNavigateWikilink }: { content: strin {/* Wikilink suggestion menu triggered by [[ */} .bn-block-group > .bn-block-outer { + counter-increment: block-number; + position: relative; +} + +.editor__blocknote-container .bn-editor > .bn-block-group > .bn-block-outer::after { + content: counter(block-number); + position: absolute; + left: -36px; + top: 0; + width: 28px; + text-align: right; + font-size: 12px; + line-height: var(--editor-line-height); + color: var(--text-faint, #999); + pointer-events: none; + user-select: none; +} + +/* --- Active block highlight --- */ +.editor__blocknote-container .bn-block-outer[data-is-active="true"] > .bn-block > .bn-block-content { + background: var(--bg-hover-subtle, rgba(128, 128, 128, 0.06)); + border-radius: 3px; +} + +/* Dim non-active block numbers, highlight active */ +.editor__blocknote-container .bn-block-outer[data-is-active="true"]::after { + color: var(--text-secondary, #666); } /* Override BlockNote's default line-height on block-outer so our theme controls it */