Skip to content

Commit 597542f

Browse files
committed
Begin Refactor
1 parent 938e279 commit 597542f

23 files changed

+631
-880
lines changed

Sources/CodeEditSourceEditor/CodeEditUI/PanelTextField.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ struct PanelTextField<LeadingAccessories: View, TrailingAccessories: View>: View
3333

3434
var onClear: (() -> Void)
3535

36-
var hasValue: Bool
37-
3836
init(
3937
_ label: String,
4038
text: Binding<String>,
@@ -43,8 +41,7 @@ struct PanelTextField<LeadingAccessories: View, TrailingAccessories: View>: View
4341
@ViewBuilder trailingAccessories: () -> TrailingAccessories? = { EmptyView() },
4442
helperText: String? = nil,
4543
clearable: Bool? = false,
46-
onClear: (() -> Void)? = {},
47-
hasValue: Bool? = false
44+
onClear: (() -> Void)? = {}
4845
) {
4946
self.label = label
5047
_text = text
@@ -54,15 +51,14 @@ struct PanelTextField<LeadingAccessories: View, TrailingAccessories: View>: View
5451
self.helperText = helperText ?? nil
5552
self.clearable = clearable ?? false
5653
self.onClear = onClear ?? {}
57-
self.hasValue = hasValue ?? false
5854
}
5955

6056
@ViewBuilder
6157
public func selectionBackground(
6258
_ isFocused: Bool = false
6359
) -> some View {
64-
if self.controlActive != .inactive || !text.isEmpty || hasValue {
65-
if isFocused || !text.isEmpty || hasValue {
60+
if self.controlActive != .inactive || !text.isEmpty {
61+
if isFocused || !text.isEmpty {
6662
Color(.textBackgroundColor)
6763
} else {
6864
if colorScheme == .light {
@@ -135,7 +131,7 @@ struct PanelTextField<LeadingAccessories: View, TrailingAccessories: View>: View
135131
)
136132
.overlay(
137133
RoundedRectangle(cornerRadius: 6)
138-
.stroke(isFocused || !text.isEmpty || hasValue ? .tertiary : .quaternary, lineWidth: 1.25)
134+
.stroke(isFocused || !text.isEmpty ? .tertiary : .quaternary, lineWidth: 1.25)
139135
.clipShape(RoundedRectangle(cornerRadius: 6))
140136
.disabled(true)
141137
.edgesIgnoringSafeArea(.all)

Sources/CodeEditSourceEditor/Controller/TextViewController+Cursor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AppKit
1111
extension TextViewController {
1212
/// Sets new cursor positions.
1313
/// - Parameter positions: The positions to set. Lines and columns are 1-indexed.
14-
public func setCursorPositions(_ positions: [CursorPosition]) {
14+
public func setCursorPositions(_ positions: [CursorPosition], scrollToVisible: Bool = false) {
1515
if isPostingCursorNotification { return }
1616
var newSelectedRanges: [NSRange] = []
1717
for position in positions {
@@ -33,6 +33,10 @@ extension TextViewController {
3333
}
3434
}
3535
textView.selectionManager.setSelectedRanges(newSelectedRanges)
36+
37+
if scrollToVisible {
38+
textView.scrollSelectionToVisible()
39+
}
3640
}
3741

3842
/// Update the ``TextViewController/cursorPositions`` variable with new text selections from the text view.

Sources/CodeEditSourceEditor/Controller/TextViewController+FindPanelTarget.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
// Created by Khan Winter on 3/16/25.
66
//
77

8-
import Foundation
8+
import AppKit
99
import CodeEditTextView
1010

1111
extension TextViewController: FindPanelTarget {
12+
var findPanelTargetView: NSView {
13+
textView
14+
}
15+
1216
func findPanelWillShow(panelHeight: CGFloat) {
1317
scrollView.contentInsets.top += panelHeight
1418
gutterView.frame.origin.y = -scrollView.contentInsets.top
@@ -20,7 +24,7 @@ extension TextViewController: FindPanelTarget {
2024
}
2125

2226
func findPanelModeDidChange(to mode: FindPanelMode, panelHeight: CGFloat) {
23-
scrollView.contentInsets.top += mode == .replace ? panelHeight/2 : -panelHeight
27+
scrollView.contentInsets.top += mode == .replace ? panelHeight : -(panelHeight/2)
2428
gutterView.frame.origin.y = -scrollView.contentInsets.top
2529
}
2630

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension TextViewController {
155155
self.findViewController?.showFindPanel()
156156
return nil
157157
case (0, "\u{1b}"): // Escape key
158-
self.findViewController?.findPanel.dismiss()
158+
self.findViewController?.hideFindPanel()
159159
return nil
160160
case (_, _):
161161
return event

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extension TextViewController {
7878
scrollView.contentInsets.top += additionalTextInsets?.top ?? 0
7979
scrollView.contentInsets.bottom += additionalTextInsets?.bottom ?? 0
8080

81-
scrollView.contentInsets.top += (findViewController?.isShowingFindPanel ?? false)
81+
scrollView.contentInsets.top += (findViewController?.viewModel.isShowingFindPanel ?? false)
8282
? findViewController?.panelHeight ?? 0
8383
: 0
8484
}

Sources/CodeEditSourceEditor/Find/FindPanelDelegate.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/CodeEditSourceEditor/Find/FindPanelTarget.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
// Created by Khan Winter on 3/10/25.
66
//
77

8-
import Foundation
8+
import AppKit
99
import CodeEditTextView
1010

1111
protocol FindPanelTarget: AnyObject {
1212
var emphasisManager: EmphasisManager? { get }
1313
var text: String { get }
14+
var findPanelTargetView: NSView { get }
1415

1516
var cursorPositions: [CursorPosition] { get }
16-
func setCursorPositions(_ positions: [CursorPosition])
17+
func setCursorPositions(_ positions: [CursorPosition], scrollToVisible: Bool)
1718
func updateCursorPosition()
1819

1920
func findPanelWillShow(panelHeight: CGFloat)

Sources/CodeEditSourceEditor/Find/FindViewController+FindPanelDelegate.swift

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)