Skip to content

feat: replace editor right pane with SwiftUI content area#236

Open
2ndalpha wants to merge 2 commits intomasterfrom
feat/swiftui-content-area
Open

feat: replace editor right pane with SwiftUI content area#236
2ndalpha wants to merge 2 commits intomasterfrom
feat/swiftui-content-area

Conversation

@2ndalpha
Copy link
Owner

Summary

  • Replace the XIB-bound right pane (HostsTextView + NSPredicateEditor) with SwiftUI views, following the pattern from PR feat: replace sidebar NSOutlineView with SwiftUI List #234 (sidebar replacement)
  • Add HostsTextViewRepresentable wrapping the existing HostsTextView via NSViewRepresentable with bidirectional content sync
  • Add CombinedHostsPickerView as a SwiftUI toggle list replacing the complex NSPredicateEditor for combined hosts file selection
  • Add ContentView composing the picker + text editor, and ContentInstaller as the @objc bridge

This is PR 2 of 3 in the Editor.xib modernization plan. PR 1 was #234 (sidebar). PR 3 will eliminate Editor.xib entirely.

Changes

New Swift Files

File Role
HostsTextViewRepresentable.swift NSViewRepresentable wrapping HostsTextView with content sync, syntax highlighting preference via @AppStorage, and @MainActor coordinator
CombinedHostsPickerView.swift SwiftUI toggle list of all non-combined hosts files, shown only when a CombinedHosts file is selected
ContentView.swift Composes picker (conditional) + text editor in a VStack
ContentInstaller.swift @objc bridge that replaces the right pane of the XIB split view with NSHostingView

Modified Files

File Change
HostsTextView.h/.m Add +createForProgrammaticUse factory method; extract setupColors from initWithCoder:
EditorController.m Call [ContentInstaller installIn:splitView] after SidebarInstaller
GasMask-Bridging-Header.h Add #import "HostsTextView.h"
project.pbxproj Add 4 new Swift source files

Superseded (kept alive, deferred to PR 3)

  • HostsTextController — XIB-instantiated, bindings fire on detached view (harmless)
  • CombinedHostsPredicateController + CombinedHostsPredicateEditorRowTemplate — same

Test plan

  • Launch app — editor window shows with sidebar (PR 1) and content area (this PR)
  • Click a hosts file — text editor shows contents with syntax highlighting
  • Edit text — unsaved dot appears in sidebar, Cmd+S saves
  • Toggle syntax highlighting in preferences — text view updates
  • Select a CombinedHosts file — picker appears above text editor
  • Toggle files in picker — combined contents update, unsaved dot appears
  • Select a non-combined file — picker disappears, text editor fills space
  • Read-only files (CombinedHosts, /etc/hosts) — text is not editable
  • Resize sidebar — content area fills remaining space correctly
  • Close and reopen window — content area renders correctly

Replace the XIB-bound right pane (HostsTextView + NSPredicateEditor)
with SwiftUI views while keeping the Editor.xib window shell intact.

New files:
- HostsTextViewRepresentable: NSViewRepresentable wrapping HostsTextView
  with bidirectional content sync and syntax highlighting preference
- CombinedHostsPickerView: SwiftUI toggle list replacing NSPredicateEditor
  for selecting which hosts files to combine
- ContentView: Composes picker (for CombinedHosts) + text editor
- ContentInstaller: @objc bridge installing SwiftUI into XIB split view

Changes:
- HostsTextView: Add createForProgrammaticUse factory method, extract
  setupColors from initWithCoder for reuse
- EditorController: Call ContentInstaller after SidebarInstaller
- Bridging header: Add HostsTextView.h import
- Xcode project: Add 4 new Swift source files

The old controllers (HostsTextController, CombinedHostsPredicateController,
CombinedHostsPredicateEditorRowTemplate) remain XIB-instantiated but their
views are detached from the hierarchy. Deferred to PR 3 for deletion.

This is PR 2 of 3 in the Editor.xib modernization plan.
…dHostsPickerView

- Unwrap optional return from HostsTextView.createForProgrammaticUse
  (ObjC factory methods return nullable in Swift)
- Add @ViewBuilder to pickerContent(for:) to fix opaque return type
  inference with local let bindings
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