refactor: split GhosttyNSView into per-concern extension files - #61
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
GhosttyNSViewhad 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 theGhosttyNSViewclass 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,GhosttyTerminalViewrepresentable, 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, andNSDraggingDestinationoverrides.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 existingGhosttyTerminalView.swiftentries.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 sharedmods*helpers, a handful of top-levelprivatehelper functions) were widened fromprivate/fileprivatetointernal— the minimum needed for same-type extensions across files to see them.deinit,withExternalCommittedText, andwindowDidChangeScreenstay 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 onGhosttyNSView, 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
PROGRAMA_SKIP_ZIG_BUILD=1 xcodebuild -project GhosttyTabs.xcodeproj -scheme programa -configuration Debug -destination 'platform=macOS' build→** BUILD SUCCEEDED **tests-build-and-lagspecifically 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.