Skip to content

Commit 923cb88

Browse files
committed
Added to the last commit, forgot to stage all.
1 parent b683d1c commit 923cb88

File tree

6 files changed

+198
-108
lines changed

6 files changed

+198
-108
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// FindControls.swift
3+
// CodeEditSourceEditor
4+
//
5+
// Created by Austin Condiff on 4/30/25.
6+
//
7+
8+
import SwiftUI
9+
10+
struct FindControls: View {
11+
@ObservedObject var viewModel: FindPanelViewModel
12+
var condensed: Bool
13+
14+
var body: some View {
15+
HStack(spacing: 4) {
16+
ControlGroup {
17+
Button {
18+
viewModel.moveToPreviousMatch()
19+
} label: {
20+
Image(systemName: "chevron.left")
21+
.opacity(viewModel.matchCount == 0 ? 0.33 : 1)
22+
.padding(.horizontal, condensed ? 0 : 5)
23+
}
24+
.help("Previous Match")
25+
.disabled(viewModel.matchCount == 0)
26+
Divider()
27+
.overlay(Color(nsColor: .tertiaryLabelColor))
28+
Button {
29+
viewModel.moveToNextMatch()
30+
} label: {
31+
Image(systemName: "chevron.right")
32+
.opacity(viewModel.matchCount == 0 ? 0.33 : 1)
33+
.padding(.horizontal, condensed ? 0 : 5)
34+
}
35+
.help("Next Match")
36+
.disabled(viewModel.matchCount == 0)
37+
}
38+
.controlGroupStyle(PanelControlGroupStyle())
39+
.fixedSize()
40+
Button {
41+
viewModel.dismiss?()
42+
} label: {
43+
Group {
44+
if condensed {
45+
Image(systemName: "xmark")
46+
} else {
47+
Text("Done")
48+
}
49+
}
50+
.help(condensed ? "Done" : "")
51+
.padding(.horizontal, condensed ? 0 : 5)
52+
}
53+
.buttonStyle(PanelButtonStyle())
54+
}
55+
}
56+
}

Sources/CodeEditSourceEditor/Find/PanelView/FindPanelContent.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//
2+
// FindPanelContent.swift
3+
// CodeEditSourceEditor
4+
//
5+
// Created by Austin Condiff on 5/2/25.
6+
//
7+
8+
import SwiftUI
9+
110
struct FindPanelContent: View {
211
@ObservedObject var viewModel: FindPanelViewModel
312
@FocusState.Binding var focus: FindPanelView.FindPanelFocus?
@@ -32,4 +41,4 @@ struct FindPanelContent: View {
3241
.fixedSize()
3342
}
3443
}
35-
}
44+
}

Sources/CodeEditSourceEditor/Find/PanelView/FindPanelView.swift

Lines changed: 13 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@ struct FindPanelView: View {
2222
@FocusState private var focus: FindPanelFocus?
2323

2424
var body: some View {
25-
HStack(spacing: 5) {
26-
VStack(alignment: .leading, spacing: 4) {
27-
FindSearchField(viewModel: viewModel, focus: $focus, findModePickerWidth: $findModePickerWidth)
28-
if viewModel.mode == .replace {
29-
ReplaceSearchField(viewModel: viewModel, focus: $focus, findModePickerWidth: $findModePickerWidth)
30-
}
31-
}
32-
VStack(alignment: .leading, spacing: 4) {
33-
doneNextControls
34-
if viewModel.mode == .replace {
35-
Spacer(minLength: 0)
36-
replaceControls
37-
}
38-
}
39-
.fixedSize()
25+
ViewThatFits {
26+
FindPanelContent(
27+
viewModel: viewModel,
28+
focus: $focus,
29+
findModePickerWidth: $findModePickerWidth,
30+
condensed: false
31+
)
32+
FindPanelContent(
33+
viewModel: viewModel,
34+
focus: $focus,
35+
findModePickerWidth: $findModePickerWidth,
36+
condensed: true
37+
)
4038
}
4139
.padding(.horizontal, 5)
4240
.frame(height: viewModel.panelHeight)
@@ -67,77 +65,6 @@ struct FindPanelView: View {
6765
}
6866
}
6967
}
70-
71-
@ViewBuilder private var doneNextControls: some View {
72-
HStack(spacing: 4) {
73-
ControlGroup {
74-
Button {
75-
viewModel.moveToPreviousMatch()
76-
} label: {
77-
Image(systemName: "chevron.left")
78-
.opacity(viewModel.matchCount == 0 ? 0.33 : 1)
79-
.padding(.horizontal, 5)
80-
}
81-
.disabled(viewModel.matchCount == 0)
82-
Divider()
83-
.overlay(Color(nsColor: .tertiaryLabelColor))
84-
Button {
85-
viewModel.moveToNextMatch()
86-
} label: {
87-
Image(systemName: "chevron.right")
88-
.opacity(viewModel.matchCount == 0 ? 0.33 : 1)
89-
.padding(.horizontal, 5)
90-
}
91-
.disabled(viewModel.matchCount == 0)
92-
}
93-
.controlGroupStyle(PanelControlGroupStyle())
94-
.fixedSize()
95-
Button {
96-
viewModel.dismiss?()
97-
} label: {
98-
Text("Done")
99-
.padding(.horizontal, 5)
100-
}
101-
.buttonStyle(PanelButtonStyle())
102-
}
103-
}
104-
105-
@ViewBuilder private var replaceControls: some View {
106-
HStack(spacing: 4) {
107-
ControlGroup {
108-
Button {
109-
viewModel.replace()
110-
} label: {
111-
Text("Replace")
112-
.opacity(
113-
!viewModel.isFocused
114-
|| viewModel.findText.isEmpty
115-
|| viewModel.matchCount == 0 ? 0.33 : 1
116-
)
117-
}
118-
// TODO: disable if there is not an active match
119-
.disabled(
120-
!viewModel.isFocused
121-
|| viewModel.findText.isEmpty
122-
|| viewModel.matchCount == 0
123-
)
124-
.frame(maxWidth: .infinity)
125-
126-
Divider().overlay(Color(nsColor: .tertiaryLabelColor))
127-
128-
Button {
129-
viewModel.replaceAll()
130-
} label: {
131-
Text("All")
132-
.opacity(viewModel.findText.isEmpty || viewModel.matchCount == 0 ? 0.33 : 1)
133-
}
134-
.disabled(viewModel.findText.isEmpty || viewModel.matchCount == 0)
135-
.frame(maxWidth: .infinity)
136-
}
137-
.controlGroupStyle(PanelControlGroupStyle())
138-
}
139-
.fixedSize(horizontal: false, vertical: true)
140-
}
14168
}
14269

14370
private struct FindModePickerWidthPreferenceKey: PreferenceKey {

Sources/CodeEditSourceEditor/Find/PanelView/FindSearchField.swift

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,49 @@ struct FindSearchField: View {
1111
@ObservedObject var viewModel: FindPanelViewModel
1212
@FocusState.Binding var focus: FindPanelView.FindPanelFocus?
1313
@Binding var findModePickerWidth: CGFloat
14+
var condensed: Bool
1415

1516
var body: some View {
1617
PanelTextField(
1718
"Text",
1819
text: $viewModel.findText,
1920
leadingAccessories: {
20-
FindModePicker(
21-
mode: $viewModel.mode,
22-
wrapAround: $viewModel.wrapAround
23-
)
24-
.background(GeometryReader { geometry in
25-
Color.clear.onAppear {
26-
findModePickerWidth = geometry.size.width
27-
}
28-
.onChange(of: geometry.size.width) { newWidth in
29-
findModePickerWidth = newWidth
21+
if condensed {
22+
Color.clear
23+
.frame(width: 12, height: 12)
24+
.foregroundStyle(.secondary)
25+
.padding(.leading, 8)
26+
.overlay(alignment: .leading) {
27+
FindModePicker(
28+
mode: $viewModel.mode,
29+
wrapAround: $viewModel.wrapAround
30+
)
31+
}
32+
.clipped()
33+
.overlay(alignment: .trailing) {
34+
Image(systemName: "chevron.down")
35+
.foregroundStyle(.secondary)
36+
.font(.system(size: 5, weight: .black))
37+
.padding(.leading, 4).padding(.trailing, -4)
38+
}
39+
} else {
40+
HStack(spacing: 0) {
41+
FindModePicker(
42+
mode: $viewModel.mode,
43+
wrapAround: $viewModel.wrapAround
44+
)
45+
.background(GeometryReader { geometry in
46+
Color.clear.onAppear {
47+
findModePickerWidth = geometry.size.width
48+
}
49+
.onChange(of: geometry.size.width) { newWidth in
50+
findModePickerWidth = newWidth
51+
}
52+
})
53+
.focusable(false)
54+
Divider()
3055
}
31-
})
32-
.focusable(false)
33-
Divider()
56+
}
3457
},
3558
trailingAccessories: {
3659
Divider()
@@ -41,18 +64,21 @@ struct FindSearchField: View {
4164
weight: viewModel.matchCase ? .bold : .medium
4265
))
4366
.foregroundStyle(
44-
Color(nsColor: viewModel.matchCase
67+
Color(
68+
nsColor: viewModel.matchCase
4569
? .controlAccentColor
4670
: .labelColor
47-
)
71+
)
4872
)
4973
.frame(width: 30, height: 20)
5074
})
5175
.toggleStyle(.icon)
5276
},
5377
helperText: viewModel.findText.isEmpty
5478
? nil
55-
: "\(viewModel.matchCount) \(viewModel.matchCount == 1 ? "match" : "matches")",
79+
: condensed
80+
? "\(viewModel.matchCount)"
81+
: "\(viewModel.matchCount) \(viewModel.matchCount == 1 ? "match" : "matches")",
5682
clearable: true
5783
)
5884
.controlSize(.small)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// ReplaceControls.swift
3+
// CodeEditSourceEditor
4+
//
5+
// Created by Austin Condiff on 4/30/25.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ReplaceControls: View {
11+
@ObservedObject var viewModel: FindPanelViewModel
12+
var condensed: Bool
13+
14+
var body: some View {
15+
HStack(spacing: 4) {
16+
ControlGroup {
17+
Button {
18+
viewModel.replace()
19+
} label: {
20+
Group {
21+
if condensed {
22+
Image(systemName: "arrow.turn.up.right")
23+
} else {
24+
Text("Replace")
25+
}
26+
}
27+
.opacity(
28+
!viewModel.isFocused
29+
|| viewModel.findText.isEmpty
30+
|| viewModel.matchCount == 0 ? 0.33 : 1
31+
)
32+
}
33+
.help(condensed ? "Replace" : "")
34+
.disabled(
35+
!viewModel.isFocused
36+
|| viewModel.findText.isEmpty
37+
|| viewModel.matchCount == 0
38+
)
39+
.frame(maxWidth: .infinity)
40+
41+
Divider().overlay(Color(nsColor: .tertiaryLabelColor))
42+
43+
Button {
44+
viewModel.replaceAll()
45+
} label: {
46+
Group {
47+
if condensed {
48+
Image(systemName: "text.insert")
49+
} else {
50+
Text("All")
51+
}
52+
}
53+
.opacity(viewModel.findText.isEmpty || viewModel.matchCount == 0 ? 0.33 : 1)
54+
}
55+
.help(condensed ? "Replace All" : "")
56+
.disabled(viewModel.findText.isEmpty || viewModel.matchCount == 0)
57+
.frame(maxWidth: .infinity)
58+
}
59+
.controlGroupStyle(PanelControlGroupStyle())
60+
}
61+
.fixedSize(horizontal: false, vertical: true)
62+
}
63+
}

Sources/CodeEditSourceEditor/Find/PanelView/ReplaceSearchField.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@ struct ReplaceSearchField: View {
1111
@ObservedObject var viewModel: FindPanelViewModel
1212
@FocusState.Binding var focus: FindPanelView.FindPanelFocus?
1313
@Binding var findModePickerWidth: CGFloat
14+
var condensed: Bool
1415

1516
var body: some View {
1617
PanelTextField(
1718
"Text",
1819
text: $viewModel.replaceText,
1920
leadingAccessories: {
20-
HStack(spacing: 0) {
21+
if condensed {
2122
Image(systemName: "pencil")
2223
.foregroundStyle(.secondary)
2324
.padding(.leading, 8)
24-
.padding(.trailing, 5)
25-
Text("With")
25+
} else {
26+
HStack(spacing: 0) {
27+
HStack(spacing: 0) {
28+
Image(systemName: "pencil")
29+
.foregroundStyle(.secondary)
30+
.padding(.leading, 8)
31+
.padding(.trailing, 5)
32+
Text("With")
33+
}
34+
.frame(width: findModePickerWidth, alignment: .leading)
35+
Divider()
36+
}
2637
}
27-
.frame(width: findModePickerWidth, alignment: .leading)
28-
Divider()
2938
},
3039
clearable: true
3140
)

0 commit comments

Comments
 (0)