Skip to content

Pluggable Node Navigation System - Entry/Exit Methods #28

Closed

Description

@malibio

Overview

Refactor arrow key navigation to use node-specific entry/exit methods instead of assuming all nodes behave like textareas.

Current Problem

  • Arrow navigation assumes all nodes are textarea-based
  • Hard-coded logic in NodeEditor for cursor positioning
  • No way for different node types to define custom navigation behavior
  • Complex contenteditable nodes can't integrate properly

Proposed Solution

Add optional navigation methods to BaseNode that nodes can implement:

interface NodeNavigationMethods {
  // Can this node accept keyboard navigation?
  canAcceptNavigation(): boolean;
  
  // Enter node from top (arrow down from previous node)
  enterFromTop(columnHint?: number): boolean;
  
  // Enter node from bottom (arrow up from next node)  
  enterFromBottom(columnHint?: number): boolean;
  
  // Exit node going up (cursor at first line, arrow up pressed)
  exitToTop(): { canExit: boolean; columnPosition: number };
  
  // Exit node going down (cursor at last line, arrow down pressed)
  exitToBottom(): { canExit: boolean; columnPosition: number };
  
  // Get current cursor column for cross-node consistency
  getCurrentColumn(): number;
}

Implementation Benefits

  • Node autonomy: Each node type controls its own navigation
  • Contenteditable support: Rich editors can implement proper selection handling
  • Complex widgets: Future inline widgets can define custom navigation
  • Fallback behavior: Nodes without navigation methods are skipped
  • Cleaner architecture: Remove navigation assumptions from NodeEditor

Examples

TextNode (textarea-based):

enterFromTop(columnHint = 0) {
  this.textareaRef.focus();
  this.setCursor(Math.min(columnHint, firstLine.length));
  return true;
}

exitToBottom() {
  const atLastLine = this.cursorInLastLine();
  return { canExit: atLastLine, columnPosition: this.getCurrentColumn() };
}

RichTextNode (contenteditable):

enterFromTop(columnHint = 0) {
  this.contentEditableRef.focus();
  this.setSelectionToStart(columnHint);
  return true;
}

ImageNode (non-navigable):

canAcceptNavigation() { return false; }
// Node is skipped during arrow navigation

TaskNode (checkbox + text):

enterFromTop() {
  // Focus text portion, not checkbox
  this.textRef.focus();
  return true;
}

Migration Plan

  1. Add optional navigation interface to BaseNode
  2. Implement methods in existing TextNode (textarea-based)
  3. Update NodeEditor to use node methods instead of direct textarea access
  4. Test with different node types
  5. Implement in future contenteditable and widget nodes

Dependencies

  • Current BaseNode architecture
  • Existing arrow key navigation system

Acceptance Criteria

  • BaseNode has optional navigation method interface
  • TextNode implements navigation methods for textarea
  • NodeEditor routes navigation through node methods
  • Non-navigable nodes are skipped during arrow navigation
  • Column position is preserved across different node types
  • Existing navigation behavior remains unchanged for current nodes
  • Architecture ready for contenteditable and widget implementations

Activity

  1. malibio commented on Dec 5, 2025

    @malibio
    CollaboratorAuthor

    Outdated - references ContentEditable controller which no longer exists. Arrow key navigation is implemented in textarea-controller.svelte.ts with:

    • Arrow navigation between nodes
    • Pixel offset preservation
    • Node entry/exit handling

    Any further navigation enhancements should be new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions