Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(markdown): slide the active-block marker between blocks
Elian Doran8d50573c9bd3
diff --git a/apps/client/src/widgets/type_widgets/markdown/Markdown.css b/apps/client/src/widgets/type_widgets/markdown/Markdown.cssindex de5aa72eb7..37b0a4e40c 100644--- a/apps/client/src/widgets/type_widgets/markdown/Markdown.css+++ b/apps/client/src/widgets/type_widgets/markdown/Markdown.css@@ -23,6 +23,16 @@background-repeat: no-repeat;background-position: 0.5em var(--markdown-preview-marker-top, 0);background-size: 2px var(--markdown-preview-marker-height, 0);++ /* Only while the cursor moves to another block: the hook adds the class for that update+ * alone, so the marker still resizes instantly as the block it sits in is edited. */+ &.markdown-preview-marker-moving {+ transition: background-position 150ms ease, background-size 150ms ease;++ @media (prefers-reduced-motion: reduce) {+ transition: none;+ }+ }}}diff --git a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsxindex 95dc3625ee..49dc5ac310 100644--- a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx+++ b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx@@ -282,12 +282,20 @@ function useSyncedHighlight(view: VanillaCodeMirror | null, preview: HTMLDivElemuseEffect(() => {if (!view || !preview) return;+ let current: HTMLElement | null = null;+function update() {if (!view || !preview) return;const activeLine = view.state.doc.lineAt(view.state.selection.main.head).number;const blocks = preview.querySelectorAll<HTMLElement>("[data-source-line]");const match = findActiveBlock(blocks, activeLine);+ // Animate from one block to the next, but not into or out of nothing: with no+ // marker to move from, a transition reads as the bar growing out of the top edge.+ const moving = !!current && !!match && current !== match;+ preview.classList.toggle("markdown-preview-marker-moving", moving);+ current = match;+// `offsetTop` and the marker's containing block are both the preview's padding box.preview.style.setProperty("--markdown-preview-marker-top", `${match?.offsetTop ?? 0}px`);preview.style.setProperty("--markdown-preview-marker-height", `${match?.offsetHeight ?? 0}px`);