Repository navigation
Description
Overview
When clicking a nodespace://uuid link where the target is a non-root node (e.g., a heading within a document), NodeSpace should navigate to the target's root ancestor and scroll the viewer to the target node's position. Currently, non-root node links either fail to navigate meaningfully or open the child node out of context.
Additionally, markdown #anchor links (e.g., [Section](#section-a)) are preserved as-is during import instead of being resolved to nodespace://uuid links pointing to the heading node created from that section.
Problem Statement
Current behavior:
nodespace://child-uuidnavigates to the child node directly, losing parent document context#anchorlinks in imported markdown are preserved verbatim but have no click handling — NodeSpace is not a markdown viewer, headings are separate nodes
Desired behavior:
nodespace://child-uuid→ resolve to root ancestor → navigate to root (or stay if already viewing it) → scroll viewer to child node position#anchorlinks → resolved tonodespace://heading-uuidduring import, then handled by the generic navigation above
Implementation Approach
Phase 1: Frontend — Smart navigation for non-root node links
Modify NavigationService.navigateToNode() to detect non-root targets and handle them:
- Resolve the target node and walk up
structureTree.getParent()to find the root ancestor - If the current tab is already showing that root node → just scroll to
[data-node-id="uuid"](no reload, no navigation) - If showing a different root → navigate to the root node, then scroll to the target child after the viewer renders
Key considerations:
- Scroll timing: must wait for viewer to render child nodes before calling
scrollIntoView() - This is generic behavior for ALL non-root node links, not specific to headers
Phase 2: Rust — Resolve anchor links to nodespace:// during markdown import
Modify the anchor link handling in transform_single_link_with_target():
- Build a slug-to-UUID map from heading
PreparedNodes in the current document (slugify heading content using GitHub-style slugification → node UUID) - When a
#anchorlink is encountered, look up the slug in the map - If found, transform to
nodespace://uuid(same as inter-file links) - If not found, preserve as plain text (dead anchor)
The heading nodes and their pre-assigned UUIDs are already available in PrepareContext during link transformation.
Acceptance Criteria
- Clicking
nodespace://link to a non-root node navigates to its root ancestor and scrolls to the target - If already viewing the root node, no reload occurs — just smooth scroll to target
- If viewing a different node, navigation to root occurs first, then scroll after render
- Works for any non-root node type (headers, text, tasks, etc.)
- Markdown
#anchorlinks are resolved tonodespace://uuidduring import when a matching heading node exists - Unresolved anchors (no matching heading) become plain text
- Existing
nodespace://link behavior for root nodes is unchanged - Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
- NavigationService:
packages/desktop-app/src/lib/services/navigation-service.ts—navigateToNode()andresolveNodeTarget()need modification - App Shell click handler:
packages/desktop-app/src/lib/components/layout/app-shell.svelte(line 378) — globalnodespace://link interception - BaseNode DOM:
packages/desktop-app/src/lib/design/components/base-node.svelte(line 819) — nodes havedata-node-id={nodeId}attribute - SharedNodeStore:
packages/desktop-app/src/lib/services/shared-node-store.svelte.ts—structureTree.getParent()for walking up hierarchy,findContainer()pattern for root resolution - Markdown link transformer:
packages/core/src/mcp/handlers/markdown.rs(line 314) —#anchorhandling intransform_single_link_with_target() - Markdown tests:
packages/core/src/mcp/handlers/markdown_test.rs— existing anchor link tests to update - PrepareContext:
packages/core/src/mcp/handlers/markdown.rs(line 108) — heading stack with node IDs and levels
Implementation Details
Frontend root resolution pattern (from existing findContainer in SharedNodeStore):
// Walk up structureTree to find root
let currentId = targetNodeId;
while (true) {
const parentId = structureTree.getParent(currentId);
if (!parentId || parentId === '__root__') break;
currentId = parentId;
}
// currentId is now the root nodeScroll after navigation — need to handle async render timing:
// After navigation completes, scroll to target node
requestAnimationFrame(() => {
const el = document.querySelector(`[data-node-id="${targetNodeId}"]`);
el?.scrollIntoView({ behavior: 'smooth', block: 'center' });
});Rust slug generation — GitHub-style heading slugification:
fn slugify_heading(content: &str) -> String {
content.to_lowercase()
.replace(|c: char| !c.is_alphanumeric() && c != ' ' && c != '-', "")
.replace(' ', "-")
}Non-Goals
- Custom scroll offset or highlight animation for the target node (can be added later)
- Deep-linking via URL fragment (e.g.,
nodespace://root-uuid#child-uuid) - Anchor link support in the editor (edit mode) — this is import and view mode only
Activity
malibio commentedon Feb 25, 2026
Test baseline: Frontend 3586 passed (108 files), Rust 25 passed (0 failed)
Add smart navigation for non-root node links and resolve anchor links…
Smart navigation for non-root node links with scroll-to-target (#910)
Smart navigation for non-root node links with scroll-to-target (#910)