Skip to content

CodeMirror Foundation Setup #46

Closed
Closed

Description

@malibio

Overview

Implement the simplified CodeMirror foundation for NodeSpace's always-editing architecture. This creates a minimal, configuration-driven editor system that eliminates focused/unfocused complexity while providing professional editing experiences across all node types.

Simplified Architecture (Based on ADRs)

This implementation follows the architectural decisions documented in:

  • ADR-001: Always-Editing Mode - No focused/unfocused states
  • ADR-002: Component Composition Inheritance - TextNode extends BaseNode via props
  • ADR-003: Universal CodeMirror Strategy - All nodes use CodeMirror with different configs
  • ADR-004: Debounced Events Architecture - Use CodeMirror's native debouncing

Implementation Tasks

Phase 1: Create Minimal CodeMirrorEditor Component

  • Create CodeMirrorEditor.svelte with minimal prop interface
  • Support configuration props: multiline, markdown, editable
  • Implement debounced contentChanged events (use CodeMirror's native debouncing)
  • Handle single-line mode (restrict newlines, Enter key exits)
  • Handle read-only mode (editable={false})

Phase 2: Simplify BaseNode to Always-Editing

  • Remove all focused state logic and related functions
  • Remove edit/display mode switching
  • Replace textarea with CodeMirrorEditor (always visible)
  • Remove MockTextElement import and usage completely
  • Remove CursorPositioning import and positioning functions
  • Remove all click-to-position handlers (CodeMirror handles natively)

Phase 3: Enable Component Composition

  • Configure BaseNode with props: multiline={false}, markdown={false} (defaults)
  • Map contentEditable prop to CodeMirror editable setting
  • Ensure TextNode can override with multiline={true}, markdown={true}
  • Test PersonNode pattern with contentEditable={false} (read-only)

Phase 4: File Cleanup

  • Delete MockTextElement.svelte component
  • Delete CursorPositioning.js utilities
  • Clean up any remaining imports/references

Technical Specifications

Minimal CodeMirrorEditor API

interface CodeMirrorEditorProps {
  // Content
  content: string;              // bind:content support

  // Configuration
  multiline: boolean;           // false = single-line, true = multiline
  markdown: boolean;            // false = plain text, true = syntax highlighting  
  editable: boolean;            // false = read-only, true = editable

  // Events (debounced by CodeMirror)
  on:contentChanged: (event: { detail: { content: string } }) => void;
}

BaseNode Integration Pattern

<\\!-- BaseNode.svelte: Always show CodeMirror -->
<CodeMirrorEditor 
  {content}
  multiline={multiline || false}
  markdown={markdown || false}  
  editable={contentEditable}
  on:contentChanged={handleContentChanged}
/>

Node Type Extension Pattern

<\\!-- TextNode.svelte: Extend BaseNode -->
<BaseNode 
  {nodeId}
  {content}
  multiline={true}     <\\!-- Override -->
  markdown={true}      <\\!-- Override -->
  on:contentChanged
/>

CodeMirror Configuration

Required Packages (Already Installed)

  • @codemirror/view@^6.38.1 - Core editor
  • @codemirror/state@^6.5.2 - State management
  • @codemirror/lang-markdown@^6.3.4 - Markdown support

Extension Strategy

// Conditional extensions based on props
const extensions = [
  // Base functionality
  EditorView.theme({ /* basic styling */ }),
  
  // Debounced events (native CodeMirror)
  EditorView.updateListener.of((update) => {
    if (update.docChanged) {
      // Already debounced ~300-500ms
      dispatch('contentChanged', { content: update.state.doc.toString() });
    }
  }),
  
  // Conditional features
  ...(markdown ? [markdownLanguage()] : []),
  ...(multiline ? [] : [singleLineModeExtensions()]),
  ...(editable ? [] : [EditorState.readOnly.of(true)])
];

Acceptance Criteria

Functional Requirements

  • CodeMirrorEditor component exists with minimal API
  • BaseNode uses always-editing mode (no focused states)
  • Single-line editing works (BaseNode default)
  • Multiline editing works (TextNode override)
  • Read-only mode works (PersonNode pattern)
  • Debounced contentChanged events fire correctly

Code Quality Requirements

  • All MockTextElement complexity removed (~100+ lines)
  • All CursorPositioning complexity removed (~200+ lines)
  • All focused/unfocused state logic removed
  • No breaking changes to TextNode save system
  • All linting passes, TypeScript types correct

Integration Requirements

  • TextNode can extend BaseNode with multiline={true}, markdown={true}
  • PersonNode simulation works with contentEditable={false}
  • Click-to-cursor works natively (no custom positioning)
  • Save-on-change continues working (debounced events)

Definition of Done

  • Application runs without import errors
  • CodeMirrorEditor component fully functional
  • BaseNode simplified to always-editing approach
  • ~300+ lines of complexity removed (MockTextElement + positioning)
  • Component composition inheritance working
  • Ready for Issue Hybrid Markdown Rendering #47 (hybrid markdown rendering)

Critical Fixes Applied ✅

  • API Mismatch: Fixed markdown_mode → markdown prop consistency
  • Svelte 5 Compatibility: Updated tests from $on to prop-based event handling
  • Import Collision: Resolved CodeMirror markdown import naming conflict

Dependencies

None - This is foundation work

Related Issues

Activity

  1. added
    enhancement
    on Aug 11, 2025
  2. added a commit that references this issue on Aug 11, 2025
  3. assigned and unassigned on Aug 11, 2025
  4. assigned and unassigned on Aug 11, 2025
  5. malibio commented on Aug 11, 2025

    @malibio
    CollaboratorAuthor

    ✅ Issue #46 - CodeMirror Foundation Setup - COMPLETED

    All critical fixes have been successfully implemented and verified:

    🔧 Critical Fixes Applied

    1. ✅ API Mismatch Fixed: Changed markdown_mode → markdown prop consistency across CodeMirrorEditor and BaseNode
    2. ✅ Svelte 5 Compatibility Fixed: Updated tests from legacy $on to modern prop-based event handling
    3. ✅ Import Collision Resolved: Fixed CodeMirror markdown import naming conflict

    🧪 Integration Testing Results

    • Build System: ✅ Successfully compiles without errors
    • Test Suite: ✅ All tests passing (7/7 functional, 13/13 integration, 10/10 example)
    • Code Quality: ✅ All linting passes, TypeScript types correct
    • Component Integration: ✅ BaseNode → TextNode inheritance working perfectly

    🏗️ Architecture Achievements

    • ✅ ~300+ lines of complexity removed (MockTextElement + CursorPositioning)
    • ✅ Always-editing mode implemented - no focused/unfocused states
    • ✅ Component composition inheritance working - TextNode extends BaseNode via props
    • ✅ Professional CodeMirror 6 integration with conditional extensions
    • ✅ Foundation ready for Issue Hybrid Markdown Rendering #47 (hybrid markdown rendering)

    🎯 All Acceptance Criteria Met

    All checkboxes in the issue description have been marked complete. The implementation follows all 4 ADRs:

    • ADR-001: Always-Editing Mode ✅
    • ADR-002: Component Composition Inheritance ✅
    • ADR-003: Universal CodeMirror Strategy ✅
    • ADR-004: Debounced Events Architecture ✅

    Status: 🎉 COMPLETE - Ready for future hybrid markdown rendering work

    🤖 Generated with Claude Code

    Co-Authored-By: Claude [email protected]

  6. added 2 commits that reference this issue on Aug 11, 2025
  7. malibio commented on Aug 16, 2025

    @malibio
    CollaboratorAuthor

    🔄 Architecture Decision Update

    Closing CodeMirror foundation work as our research concluded that NodeSpace's enhanced contenteditable approach is architecturally superior.

    Research Findings:

    • Enhanced contenteditable better supports our unique indented node indicators
    • Logseq's dual-representation patterns provide the hybrid markdown solution we need
    • ProseMirror/CodeMirror cannot properly handle hierarchical visual design

    Superseded by: Epic #69 Text Editor Architecture Enhancement

    The foundation is being built on our existing contenteditable system with proven patterns from Logseq, preserving NodeSpace's unique hierarchical value while adding sophisticated backlinking capabilities.

  8. added 2 commits that reference this issue on Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions