Skip to content

Soft Newline + Markdown Detection (Shift-Enter intelligence) #59

Closed

Description

@malibio

Phase 2.2: Soft Newline + Markdown Detection (Shift-Enter intelligence)

Parent Epic: #54
Depends on: #55, #56 (pattern detection)
Parallel with: #58 (uses shared pattern detection)
Integrates with: #57

Overview

Implement intelligent soft newline behavior where Shift-Enter creates a new line within the current node, but if the user then types markdown syntax, the system automatically creates a new appropriate node type instead.

Parallel Development Note

✅ Can develop in parallel with #58 using shared pattern detection interfaces from #56. Both features handle different user input scenarios and can coordinate through well-defined APIs.

Context

This feature enhances the natural typing flow by making Shift-Enter context-aware:

Natural Workflow:
1. User types: "Project overview:"
2. User presses Shift-Enter (soft newline - stays in same node)  
3. User continues: "- First task"
4. System detects markdown after soft newline
5. Creates new child node with "First task" content
6. Maintains natural typing flow without interruption

Result: 
Node A: "Project overview:"
├─ Node B: "First task"  ← Automatically created and indented

Key Innovation: Context-Aware Soft Newlines

Transform Shift-Enter from simple line breaks into intelligent content creation:

  • Immediate mode: Shift-Enter creates soft newline within current node
  • Markdown detection: Typing markdown syntax after soft newline triggers node creation
  • Smart conversion: Different markdown patterns create appropriate node types
  • Natural flow: Maintains typing rhythm without mode switches

Implementation Approach

Soft Newline Detection System

interface SoftNewlineProcessor {
  // Track soft newline state
  trackSoftNewline(event: KeyboardEvent): boolean;
  
  // Monitor content after soft newline
  monitorPostSoftlineContent(content: string): ContentAnalysis;
  
  // Convert to appropriate node type
  convertToNewNode(content: string, nodeType: NodeType): Promise<NodeCreation>;
}

interface ContentAnalysis {
  hasMarkdownSyntax: boolean;
  detectedPattern: MarkdownPattern | null;
  suggestedNodeType: NodeType;
  cleanedContent: string;
}

Markdown Pattern Integration

// Leverage pattern detection from #56
interface PostSoftlineDetection {
  // Common patterns after soft newlines
  bulletPoint: /^- (.+)$/,       // → child node
  header: /^#{1,3} (.+)$/,       // → header node  
  blockquote: /^> (.+)$/,        // → quote node
  codeBlock: /^```(.*)$/,        // → code node
  regularText: /^[^->#`].*/      // → sibling text node
}

Technical Architecture

Soft Newline State Management

class SoftNewlineManager {
  private isInSoftNewlineMode: boolean = false;
  private softNewlineContent: string = '';
  private originalNodeId: string = '';
  
  handleShiftEnter(event: KeyboardEvent) {
    // Enter soft newline mode
    this.isInSoftNewlineMode = true;
    this.trackSubsequentInput();
  }
  
  handleSubsequentInput(event: InputEvent) {
    if (\!this.isInSoftNewlineMode) return;
    
    // Analyze content after soft newline
    const analysis = this.analyzePostSoftlineContent(event.data);
    
    if (analysis.hasMarkdownSyntax) {
      this.convertToNewNode(analysis);
    }
  }
}

Node Creation Decision Tree

graph TD
    A[Shift-Enter Pressed] --> B[Enter Soft Newline Mode]
    B --> C[Monitor Next Input]
    C --> D{Markdown Detected?}
    D -->|No| E[Continue Soft Newline]
    D -->|Yes| F[Analyze Pattern Type]
    F --> G{Pattern Type?}
    G -->|"- item"| H[Create Child Node via #58]
    G -->|"# header"| I[Create Header Sibling]
    G -->|"> quote"| J[Create Quote Sibling]
    G -->|"```"| K[Create Code Block]
    G -->|Regular text| L[Create Text Sibling]
Loading

User Experience Flows

Smart Bullet Creation

User Experience:
1. User in text node: "Project planning"
2. Presses Shift-Enter → soft newline within current node
3. Types: "- Research phase" 
4. System detects bullet pattern after soft newline
5. Creates child node relationship (coordinates with #58)
6. Content becomes: "Research phase" (indented as child)

Visual Result:
Project planning
├─ Research phase  ← Auto-created child node

Header Creation Flow

User Experience:  
1. User in text node: "Document sections"
2. Presses Shift-Enter → soft newline
3. Types: "## Implementation Details"
4. System detects header pattern
5. Creates new sibling node with header styling
6. Content becomes: "Implementation Details" (large header font)

Visual Result:
Document sections
Implementation Details  ← Auto-created header sibling

Mixed Content Flow

User Experience:
1. User types: "Meeting notes:"
2. Shift-Enter, types: "- Action items"  → Child node created
3. Shift-Enter, types: "> Important quote"  → Quote sibling created  
4. Shift-Enter, types: "Follow-up tasks:"  → Text sibling created

Visual Result:
Meeting notes:
├─ Action items
│  > Important quote  
│  Follow-up tasks:

Integration Points

Pattern Detection Coordination (#56)

  • Use shared pattern recognition APIs
  • Subscribe to markdown pattern events
  • Handle pattern parsing in post-softline context

Bullet Conversion Coordination (#58)

WYSIWYG Display Integration (#57)

  • Apply visual formatting to newly created nodes
  • Maintain syntax hiding for created content
  • Coordinate visual updates during node creation

Acceptance Criteria

Soft Newline Behavior

  • Shift-Enter creates soft newline within current node (no new node)
  • Regular text typed after soft newline continues in same node
  • Cursor positioning is accurate within multi-line content
  • Undo preserves soft newline state correctly

Markdown Detection & Conversion

  • - item after soft newline creates child node (coordinates with Smart Bullet-to-Node Conversion (- item → child node) #58)
  • # header after soft newline creates header sibling node
  • > quote after soft newline creates blockquote sibling node
  • ``` after soft newline creates code block sibling node
  • Regular text creates normal text sibling node

User Experience

  • Conversion feels natural and predictable during typing
  • No delays or visual artifacts during node creation
  • Users can discover soft newline + markdown patterns intuitively
  • Typing flow is maintained without interruption
  • Undo/redo works correctly across node creation boundaries

Performance & Integration

Testing Strategy

Unit Tests

  • Soft newline state tracking
  • Markdown pattern detection post-softline
  • Node creation decision logic
  • Content analysis algorithms

Integration Tests

User Experience Tests

  • Natural typing flow scenarios
  • Mixed content creation workflows
  • Complex document composition
  • Edge cases and error recovery

Coordination Requirements

Shared APIs with #58

interface BulletCoordination {
  // Delegate bullet creation to #58 systems
  handlePostSoftlineBullet(content: string, parentNodeId: string): Promise<Node>;
  
  // Share bullet pattern recognition
  isBulletPattern(content: string): boolean;
}

Pattern Detection Integration

interface PatternDetectionIntegration {
  // Analyze content in post-softline context
  analyzePostSoftlineContent(content: string): PatternAnalysis;
  
  // Subscribe to pattern events
  onPatternDetected(callback: (pattern: MarkdownPattern) => void): void;
}

Node Creation Coordination

  • Work with existing node creation APIs
  • Maintain event dispatching consistency
  • Preserve keyboard shortcut functionality
  • Coordinate visual updates

Resources & References

NodeSpace Systems

  • Keyboard handlers: Existing Shift-Enter and Enter key behaviors
  • Node creation: APIs for creating sibling and child nodes
  • Content management: Text content handling and state management

User Experience Patterns

  • Notion: Soft newlines with smart block creation
  • Obsidian: Context-aware markdown detection
  • Typora: Seamless markdown syntax conversion

Technical Integration

Definition of Done

  • Shift-Enter creates intelligent soft newlines with markdown detection
  • All major markdown patterns trigger appropriate node creation
  • Coordination with bullet conversion (Smart Bullet-to-Node Conversion (- item → child node) #58) is seamless and consistent
  • User experience feels natural and enhances productivity
  • Performance is fast with no typing delays or visual artifacts
  • Integration with pattern detection and visual systems is solid
  • Comprehensive test coverage including complex user workflows
  • Ready to integrate with multi-line block behavior (Multi-line Block Behavior (quotes, code blocks) #60)

This soft newline intelligence transforms Shift-Enter from a simple line break into a powerful content creation tool that enhances NodeSpace's typing experience while maintaining natural workflow patterns.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Activity

  1. added
    enhancement
    on Aug 11, 2025
  2. self-assigned this
    on Aug 12, 2025
  3. malibio commented on Aug 16, 2025

    @malibio
    CollaboratorAuthor

    ✅ COMPLETED - Part of Epic #63 which has been successfully implemented. The ContentEditable foundation with smart markdown features is working correctly.

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