Skip to content

Commit b683d1c

Browse files
committed
Remove Hard Dependency on TextViewController
1 parent d23caf6 commit b683d1c

File tree

9 files changed

+27
-19
lines changed

9 files changed

+27
-19
lines changed

Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/CodeEditSourceEditor/Find/FindPanelTarget.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import AppKit
99
import CodeEditTextView
1010

1111
protocol FindPanelTarget: AnyObject {
12-
var emphasisManager: EmphasisManager? { get }
13-
var text: String { get }
12+
var textView: TextView! { get }
1413
var findPanelTargetView: NSView { get }
1514

1615
var cursorPositions: [CursorPosition] { get }

Sources/CodeEditSourceEditor/Find/PanelView/FindSearchField.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct FindSearchField: View {
5656
clearable: true
5757
)
5858
.controlSize(.small)
59+
.fixedSize(horizontal: false, vertical: true)
5960
.focused($focus, equals: .find)
6061
.onSubmit {
6162
viewModel.moveToNextMatch()

Sources/CodeEditSourceEditor/Find/PanelView/ReplaceSearchField.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct ReplaceSearchField: View {
3030
clearable: true
3131
)
3232
.controlSize(.small)
33+
.fixedSize(horizontal: false, vertical: true)
3334
.focused($focus, equals: .replace)
3435
}
3536
}

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Emphasis.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CodeEditTextView
99

1010
extension FindPanelViewModel {
1111
func addMatchEmphases(flashCurrent: Bool) {
12-
guard let target = target, let emphasisManager = target.emphasisManager else {
12+
guard let target = target, let emphasisManager = target.textView.emphasisManager else {
1313
return
1414
}
1515

@@ -33,7 +33,7 @@ extension FindPanelViewModel {
3333

3434
func flashCurrentMatch() {
3535
guard let target = target,
36-
let emphasisManager = target.emphasisManager,
36+
let emphasisManager = target.textView.emphasisManager,
3737
let currentFindMatchIndex else {
3838
return
3939
}
@@ -59,6 +59,6 @@ extension FindPanelViewModel {
5959
}
6060

6161
func clearMatchEmphases() {
62-
target?.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
62+
target?.textView.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
6363
}
6464
}

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Find.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension FindPanelViewModel {
2929
return
3030
}
3131

32-
let text = target.text
32+
let text = target.textView.string
3333
let matches = regex.matches(in: text, range: NSRange(location: 0, length: text.utf16.count))
3434

3535
self.findMatches = matches.map(\.range)

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Replace.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ extension FindPanelViewModel {
1414
func replace() {
1515
guard let target = target,
1616
let currentFindMatchIndex,
17-
!findMatches.isEmpty,
18-
let textViewController = target as? TextViewController else {
17+
!findMatches.isEmpty else {
1918
return
2019
}
2120

22-
replaceMatch(index: currentFindMatchIndex, textView: textViewController.textView, matches: &findMatches)
21+
replaceMatch(index: currentFindMatchIndex, textView: target.textView, matches: &findMatches)
2322

2423
self.findMatches = findMatches.enumerated().filter({ $0.offset != currentFindMatchIndex }).map(\.element)
2524
self.currentFindMatchIndex = findMatches.isEmpty ? nil : (currentFindMatchIndex) % findMatches.count
@@ -30,21 +29,20 @@ extension FindPanelViewModel {
3029

3130
func replaceAll() {
3231
guard let target = target,
33-
!findMatches.isEmpty,
34-
let textViewController = target as? TextViewController else {
32+
!findMatches.isEmpty else {
3533
return
3634
}
3735

38-
textViewController.textView.undoManager?.beginUndoGrouping()
39-
textViewController.textView.textStorage.beginEditing()
36+
target.textView.undoManager?.beginUndoGrouping()
37+
target.textView.textStorage.beginEditing()
4038

4139
var sortedMatches = findMatches.sorted(by: { $0.location < $1.location })
4240
for (idx, _) in sortedMatches.enumerated().reversed() {
43-
replaceMatch(index: idx, textView: textViewController.textView, matches: &sortedMatches)
41+
replaceMatch(index: idx, textView: target.textView, matches: &sortedMatches)
4442
}
4543

46-
textViewController.textView.textStorage.endEditing()
47-
textViewController.textView.undoManager?.endUndoGrouping()
44+
target.textView.textStorage.endEditing()
45+
target.textView.undoManager?.endUndoGrouping()
4846

4947
if let lastMatch = sortedMatches.last {
5048
target.setCursorPositions(

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ class FindPanelViewModel: ObservableObject {
8181
// If the textview is first responder, exit fast
8282
if target?.findPanelTargetView.window?.firstResponder === target?.findPanelTargetView {
8383
// If the text view has focus, just clear visual emphases but keep our find matches
84-
target?.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
84+
target?.textView.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
8585
return
8686
}
8787

8888
// Clear existing emphases before performing new find
89-
target?.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
89+
target?.textView.emphasisManager?.removeEmphases(for: EmphasisGroup.find)
9090
find()
9191
}
9292
}

Sources/CodeEditSourceEditor/Minimap/MinimapView+DocumentVisibleView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension MinimapView {
2424
/// The ``scrollView`` uses the scroll percentage calculated for the first case, and scrolls its content to that
2525
/// percentage. The ``scrollView`` is only modified if the minimap is longer than the container view.
2626
func updateDocumentVisibleViewPosition() {
27-
guard let textView = textView, let editorScrollView = textView.enclosingScrollView, let layoutManager else {
27+
guard let textView = textView, let editorScrollView = textView.enclosingScrollView else {
2828
return
2929
}
3030

0 commit comments

Comments
 (0)