Skip to content

refactor: split GhosttyNSView into per-concern extension files - #61

Merged
arzafran merged 1 commit into
mainfrom
refactor/tc5-split-ghostty-nsview
Jul 8, 2026
Merged

refactor: split GhosttyNSView into per-concern extension files#61
arzafran merged 1 commit into
mainfrom
refactor/tc5-split-ghostty-nsview

Conversation

@arzafran

@arzafran arzafran commented Jul 8, 2026

Copy link
Copy Markdown
Member

What this does

GhosttyNSView had grown into a single 3,410-line class inside a 12,067-line file, mixing keyboard input, mouse handling, drag-and-drop, and accessibility support in one place. This splits those four concerns into their own files so each one is easier to find, read, and change without scrolling past unrelated code. Nothing about how the app behaves changes — this is a pure reorganization.

Summary

  • Sources/GhosttyTerminalView.swift: 12,067 → 9,496 lines. Keeps the GhosttyNSView class declaration, stored properties, deinit, init, and small helpers shared across the split files (mods helpers, windowDidChangeScreen), plus all other unrelated types in the file (TerminalSurface, GhosttyApp, GhosttyTerminalView representable, etc.).
  • Sources/GhosttyTerminalView+Keyboard.swift (new, 1,181 lines): keyboard copy-mode, clipboard actions, and the typing-latency-critical key path (performKeyEquivalent, keyDown, keyUp, flagsChanged, key-encoding helpers).
  • Sources/GhosttyTerminalView+Mouse.swift (new, 997 lines): mouse down/dragged/up, scroll wheel, cmd-click path hover, context menu, and tracking-area maintenance.
  • Sources/GhosttyTerminalView+DragDrop.swift (new, 278 lines): drop-plan resolution, dropped-file/pasteboard insertion, and NSDraggingDestination overrides.
  • Sources/GhosttyTerminalView+Accessibility.swift (new, 222 lines): AX text-area exposure so voice-input tools can read/insert terminal text, plus first-responder focus handling.
  • GhosttyTabs.xcodeproj/project.pbxproj: registers the 4 new files in the build target, mirroring the existing GhosttyTerminalView.swift entries.

All method bodies moved verbatim (no logic changes, no wrappers, no reordering). Members that are used across the new file boundary (e.g. surface, keyTextAccumulator, wordPathHoverActive, the shared mods* helpers, a handful of top-level private helper functions) were widened from private/fileprivate to internal — the minimum needed for same-type extensions across files to see them. deinit, withExternalCommittedText, and windowDidChangeScreen stay on the primary class declaration (deinit cannot live in an extension; the other two are called from code that stays put). Zero call-site indirection — everything is still a direct method call on GhosttyNSView, so the typing-latency contract (CLAUDE.md) is respected. TerminalSurface.forceRefresh() (a separate class, hot on every keystroke) is untouched.

Line-count math: 12,067 (original) → 9,496 + 1,181 + 997 + 278 + 222 = 12,174 lines across 5 files. The +107 lines are import headers and extension GhosttyNSView { } wrappers repeated in each new file, plus a short doc comment at the top of each.

Nuclear-review finding TC5.

Test Plan

  • Local Debug build green: PROGRAMA_SKIP_ZIG_BUILD=1 xcodebuild -project GhosttyTabs.xcodeproj -scheme programa -configuration Debug -destination 'platform=macOS' build** BUILD SUCCEEDED **
  • CI is the real arbiter here. tests-build-and-lag specifically guards the typing-latency path this refactor touches — it is the key check to watch. Note: this job is known-flaky on the runner; re-run it once before treating a failure as real.

Keyboard/copy-mode/key path, mouse/cmd-click, drag-drop, and
accessibility clusters move verbatim to same-type extension files; the
class declaration, stored properties, deinit, and shared helpers stay.
Zero call-site indirection - the typing-latency contract (CLAUDE.md) is
respected; TerminalSurface.forceRefresh untouched. Visibility widened
only where the split crosses the new file boundary. Nuclear-review TC5.
@arzafran
arzafran merged commit bdbdaac into main Jul 8, 2026
8 checks passed
@arzafran
arzafran deleted the refactor/tc5-split-ghostty-nsview branch July 10, 2026 16:05
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.

1 participant