Skip to content

refactor: replace CodeEditSourceEditor with native NSTextView editor#471

Open
datlechin wants to merge 1 commit intomainfrom
refactor/native-nstextview-editor
Open

refactor: replace CodeEditSourceEditor with native NSTextView editor#471
datlechin wants to merge 1 commit intomainfrom
refactor/native-nstextview-editor

Conversation

@datlechin
Copy link
Collaborator

Summary

New editor architecture (Apple-standard patterns)

Component File LOC Apple Pattern
TPTextView Views/Editor/TPTextView.swift 227 NSTextView subclass (minimal overrides)
TPSyntaxHighlighter Views/Editor/TPSyntaxHighlighter.swift 455 Temporary attributes on NSLayoutManager
TPLineNumberView Views/Editor/TPLineNumberView.swift 518 NSRulerView subclass
TPEditorView Views/Editor/TPEditorView.swift 204 NSViewRepresentable
TPEditorTheme Views/Editor/TPEditorTheme.swift 33 Value type
TPEditorConfiguration Views/Editor/TPEditorConfiguration.swift 43 Value type
TPEditorDelegate Views/Editor/TPEditorDelegate.swift 20 Protocol with defaults

What we gain for free from NSTextView

  • Horizontal scrolling via NSTextContainer.widthTracksTextView = false (no workarounds)
  • Find/Replace via usesFindBar = true (built-in, zero code)
  • Home/End keys (built-in NSResponder)
  • Undo/Redo via allowsUndo = true (built-in NSUndoManager)
  • Accessibility (VoiceOver)
  • Large file performance via allowsNonContiguousLayout = true

Files changed

  • 7 new TP* editor files (1,496 LOC)
  • 20 modified — adapted Vim mode, AI suggestions, event routing, completion, theme, coordinator to NSTextView API; replaced CursorPosition with NSRange
  • 252+ deleted — LocalPackages/CodeEditSourceEditor, LocalPackages/CodeEditLanguages, TableProEditorTheme.swift

Test plan

  • Type SQL — syntax highlighting works (keywords, strings, comments, numbers)
  • Paste long line — horizontal scrolling works
  • Cmd+F — Find Bar appears
  • Cmd+Z — undo works
  • Home/End keys — cursor moves to line start/end
  • Enable Vim mode — Normal/Insert/Visual modes work
  • AI inline suggestions — ghost text appears after typing
  • Right-click — AI context menu (Explain, Optimize)
  • Line numbers — display and update correctly
  • Word wrap toggle — switches between wrap and horizontal scroll
  • Large file (>100KB) — no freeze
  • Tab switch — editor state preserved
  • Read-only previews (SQL Review, SQL Import) — display with highlighting

Closes #448

Replace the 252-file CodeEditSourceEditor/CodeEditTextView third-party
dependency (25K+ LOC) with a native NSTextView-based SQL editor (~1,500 LOC).

- TPTextView: NSTextView subclass with Apple-standard horizontal scrolling,
  built-in Find Bar, auto-indent, bracket matching
- TPSyntaxHighlighter: temporary attributes on NSLayoutManager (Apple pattern)
- TPLineNumberView: NSRulerView subclass for line numbers
- TPEditorView: SwiftUI NSViewRepresentable wrapper
- Adapt Vim mode, AI suggestions, context menu to NSTextView API
- Replace CursorPosition (CESS type) with NSRange throughout
- Remove LocalPackages/CodeEditSourceEditor (1.5GB)
- Remove LocalPackages/CodeEditLanguages

Fixes #448 (horizontal scrolling broken due to CETV variable shadowing bug)
Fixes #448 (Home/End keys not working)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Home and End keys don't work in the SQL editor

1 participant