Skip to content

Commit 6e57297

Browse files
committed
Merge branch 'release/0.9.1'
2 parents f359dc7 + d61edbb commit 6e57297

File tree

5 files changed

+128
-53
lines changed

5 files changed

+128
-53
lines changed

Core/Sources/SuggestionWidget/SuggestionPanelView.swift

+2-43
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ final class SuggestionPanelViewModel: ObservableObject {
114114

115115
struct SuggestionPanelView: View {
116116
@ObservedObject var viewModel: SuggestionPanelViewModel
117-
@Namespace var namespace
118117

119118
var body: some View {
120119
VStack(spacing: 0) {
@@ -142,26 +141,6 @@ struct SuggestionPanelView: View {
142141
.fixedSize(horizontal: false, vertical: true)
143142
.allowsHitTesting(viewModel.isPanelDisplayed)
144143
.preferredColorScheme(viewModel.colorScheme)
145-
.matchedGeometryEffect(id: "suggestion", in: namespace)
146-
} else {
147-
Button(action: {
148-
viewModel.activeTab = .suggestion
149-
}, label: {
150-
HStack {
151-
Image(systemName: "lightbulb.fill")
152-
Text("Suggestion")
153-
}
154-
.padding(.horizontal, 16)
155-
.padding(.vertical, 8)
156-
.background(
157-
Color.userChatContentBackground,
158-
in: RoundedRectangle(cornerRadius: 8, style: .continuous)
159-
)
160-
.fixedSize(horizontal: false, vertical: true)
161-
})
162-
.buttonStyle(.plain)
163-
.xcodeStyleFrame()
164-
.matchedGeometryEffect(id: "suggestion", in: namespace)
165144
}
166145
}
167146

@@ -171,27 +150,7 @@ struct SuggestionPanelView: View {
171150
.frame(maxWidth: .infinity, maxHeight: Style.panelHeight)
172151
.fixedSize(horizontal: false, vertical: true)
173152
.allowsHitTesting(viewModel.isPanelDisplayed)
174-
.preferredColorScheme(viewModel.colorScheme)
175-
.matchedGeometryEffect(id: "chat", in: namespace)
176-
} else {
177-
Button(action: {
178-
viewModel.activeTab = .chat
179-
}, label: {
180-
HStack {
181-
Image(systemName: "ellipsis.bubble.fill")
182-
Text("Chat")
183-
}
184-
.padding(.horizontal, 16)
185-
.padding(.vertical, 8)
186-
.background(
187-
Color.userChatContentBackground,
188-
in: RoundedRectangle(cornerRadius: 8, style: .continuous)
189-
)
190-
.fixedSize(horizontal: false, vertical: true)
191-
})
192-
.buttonStyle(.plain)
193-
.xcodeStyleFrame()
194-
.matchedGeometryEffect(id: "chat", in: namespace)
153+
.preferredColorScheme(viewModel.colorScheme)
195154
}
196155
}
197156
}
@@ -225,7 +184,7 @@ struct CommandButtonStyle: ButtonStyle {
225184
configuration.label
226185
.padding(.vertical, 4)
227186
.padding(.horizontal, 8)
228-
.foregroundColor(.white)
187+
.foregroundColor(.white)
229188
.background(
230189
RoundedRectangle(cornerRadius: 4, style: .continuous)
231190
.fill(color.opacity(configuration.isPressed ? 0.8 : 1))

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ public final class SuggestionWidgetController {
4343
return it
4444
}()
4545

46+
private lazy var tabWindow = {
47+
let it = NSWindow(
48+
contentRect: .zero,
49+
styleMask: .borderless,
50+
backing: .buffered,
51+
defer: false
52+
)
53+
it.isReleasedWhenClosed = false
54+
it.isOpaque = false
55+
it.backgroundColor = .clear
56+
it.level = .floating
57+
it.hasShadow = true
58+
it.contentView = NSHostingView(
59+
rootView: TabView(panelViewModel: suggestionPanelViewModel)
60+
)
61+
it.setIsVisible(true)
62+
return it
63+
}()
64+
4665
private lazy var panelWindow = {
4766
let it = CanBecomeKeyWindow(
4867
contentRect: .zero,
@@ -135,6 +154,7 @@ public final class SuggestionWidgetController {
135154
{
136155
self.widgetWindow.alphaValue = 0
137156
self.panelWindow.alphaValue = 0
157+
self.tabWindow.alphaValue = 0
138158
}
139159
}
140160
}
@@ -307,6 +327,7 @@ extension SuggestionWidgetController {
307327
self.updateWindowLocation(animated: false)
308328
panelWindow.orderFront(nil)
309329
widgetWindow.orderFront(nil)
330+
tabWindow.orderFront(nil)
310331
311332
if notification.name == kAXFocusedUIElementChangedNotification {
312333
sourceEditorMonitorTask?.cancel()
@@ -376,6 +397,7 @@ extension SuggestionWidgetController {
376397
func hide() {
377398
panelWindow.alphaValue = 0
378399
widgetWindow.alphaValue = 0
400+
tabWindow.alphaValue = 0
379401
}
380402

381403
guard UserDefaults.shared.value(for: \.suggestionPresentationMode) == .floatingWidget
@@ -402,8 +424,8 @@ extension SuggestionWidgetController {
402424
activeScreen: firstScreen
403425
)
404426
widgetWindow.setFrame(result.widgetFrame, display: false, animate: animated)
405-
panelWindow.setFrame(result.panelFrame, display: true, animate: animated)
406-
427+
panelWindow.setFrame(result.panelFrame, display: false, animate: animated)
428+
tabWindow.setFrame(result.tabFrame, display: false, animate: animated)
407429
suggestionPanelViewModel.alignTopToAnchor = result.alignPanelTopToAnchor
408430
case .alignToTextCursor:
409431
let result = UpdateLocationStrategy.AlignToTextCursor().framesForWindows(
@@ -414,11 +436,13 @@ extension SuggestionWidgetController {
414436
)
415437
widgetWindow.setFrame(result.widgetFrame, display: false, animate: animated)
416438
panelWindow.setFrame(result.panelFrame, display: false, animate: animated)
439+
tabWindow.setFrame(result.tabFrame, display: false, animate: animated)
417440
suggestionPanelViewModel.alignTopToAnchor = result.alignPanelTopToAnchor
418441
}
419442

420443
panelWindow.alphaValue = 1
421444
widgetWindow.alphaValue = 1
445+
tabWindow.alphaValue = 1
422446
return
423447
}
424448
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import SwiftUI
2+
3+
struct TabView: View {
4+
@ObservedObject var panelViewModel: SuggestionPanelViewModel
5+
6+
var body: some View {
7+
Group {
8+
switch panelViewModel.activeTab {
9+
case .chat:
10+
if panelViewModel.content != nil {
11+
Button(action: {
12+
panelViewModel.activeTab = .suggestion
13+
}, label: {
14+
Image(systemName: "lightbulb.fill")
15+
.frame(width: Style.widgetWidth, height: Style.widgetHeight)
16+
.background(
17+
Color.userChatContentBackground,
18+
in: Circle()
19+
)
20+
})
21+
.buttonStyle(.plain)
22+
}
23+
case .suggestion:
24+
if panelViewModel.chat != nil {
25+
Button(action: {
26+
panelViewModel.activeTab = .chat
27+
}, label: {
28+
Image(systemName: "ellipsis.bubble.fill")
29+
.frame(width: Style.widgetWidth, height: Style.widgetHeight)
30+
.background(
31+
Color.userChatContentBackground,
32+
in: Circle()
33+
)
34+
})
35+
.buttonStyle(.plain)
36+
}
37+
}
38+
}
39+
.opacity(panelViewModel.isPanelDisplayed ? 1 : 0)
40+
.preferredColorScheme(panelViewModel.colorScheme)
41+
}
42+
}
43+
44+
struct TabView_Preview: PreviewProvider {
45+
static var previews: some View {
46+
VStack {
47+
TabView(panelViewModel: .init())
48+
}
49+
.frame(width: 30)
50+
.background(Color.black)
51+
}
52+
}

Core/Sources/SuggestionWidget/WidgetPositionStrategy.swift

+46-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ enum UpdateLocationStrategy {
88
mainScreen: NSScreen,
99
activeScreen: NSScreen,
1010
editor: AXUIElement
11-
) -> (widgetFrame: CGRect, panelFrame: CGRect, alignPanelTopToAnchor: Bool) {
11+
) -> (
12+
widgetFrame: CGRect,
13+
panelFrame: CGRect,
14+
tabFrame: CGRect,
15+
alignPanelTopToAnchor: Bool
16+
) {
1217
guard let selectedRange: AXValue = try? editor
1318
.copyValue(key: kAXSelectedTextRangeAttribute),
1419
let rect: AXValue = try? editor.copyParameterizedValue(
@@ -46,7 +51,12 @@ enum UpdateLocationStrategy {
4651
editorFrame: CGRect,
4752
mainScreen: NSScreen,
4853
activeScreen: NSScreen
49-
) -> (widgetFrame: CGRect, panelFrame: CGRect, alignPanelTopToAnchor: Bool) {
54+
) -> (
55+
widgetFrame: CGRect,
56+
panelFrame: CGRect,
57+
tabFrame: CGRect,
58+
alignPanelTopToAnchor: Bool
59+
) {
5060
return HorizontalMovable().framesForWindows(
5161
y: activeScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
5262
alignPanelTopToAnchor: false,
@@ -64,7 +74,12 @@ enum UpdateLocationStrategy {
6474
editorFrame: CGRect,
6575
mainScreen: NSScreen,
6676
activeScreen: NSScreen
67-
) -> (widgetFrame: CGRect, panelFrame: CGRect, alignPanelTopToAnchor: Bool) {
77+
) -> (
78+
widgetFrame: CGRect,
79+
panelFrame: CGRect,
80+
tabFrame: CGRect,
81+
alignPanelTopToAnchor: Bool
82+
) {
6883
let maxY = max(
6984
y,
7085
activeScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
@@ -98,7 +113,16 @@ enum UpdateLocationStrategy {
98113
width: Style.panelWidth,
99114
height: Style.panelHeight
100115
)
101-
return (anchorFrame, panelFrame, alignPanelTopToAnchor)
116+
let tabFrame = CGRect(
117+
x: anchorFrame.origin.x,
118+
y: alignPanelTopToAnchor
119+
? anchorFrame.minY - Style.widgetHeight - Style.widgetPadding
120+
: anchorFrame.maxY + Style.widgetPadding,
121+
width: Style.widgetWidth,
122+
height: Style.widgetHeight
123+
)
124+
125+
return (anchorFrame, panelFrame, tabFrame, alignPanelTopToAnchor)
102126
} else {
103127
let proposedAnchorFrameOnTheLeftSide = CGRect(
104128
x: editorFrame.minX + Style.widgetPadding,
@@ -120,7 +144,15 @@ enum UpdateLocationStrategy {
120144
width: Style.panelWidth,
121145
height: Style.panelHeight
122146
)
123-
return (anchorFrame, panelFrame, alignPanelTopToAnchor)
147+
let tabFrame = CGRect(
148+
x: anchorFrame.origin.x,
149+
y: alignPanelTopToAnchor
150+
? anchorFrame.minY - Style.widgetHeight - Style.widgetPadding
151+
: anchorFrame.maxY + Style.widgetPadding,
152+
width: Style.widgetWidth,
153+
height: Style.widgetHeight
154+
)
155+
return (anchorFrame, panelFrame, tabFrame, alignPanelTopToAnchor)
124156
} else {
125157
let anchorFrame = proposedAnchorFrameOnTheRightSide
126158
let panelFrame = CGRect(
@@ -131,7 +163,15 @@ enum UpdateLocationStrategy {
131163
width: Style.panelWidth,
132164
height: Style.panelHeight
133165
)
134-
return (anchorFrame, panelFrame, alignPanelTopToAnchor)
166+
let tabFrame = CGRect(
167+
x: anchorFrame.origin.x,
168+
y: alignPanelTopToAnchor
169+
? anchorFrame.minY - Style.widgetHeight - Style.widgetPadding
170+
: anchorFrame.maxY + Style.widgetPadding,
171+
width: Style.widgetWidth,
172+
height: Style.widgetHeight
173+
)
174+
return (anchorFrame, panelFrame, tabFrame, alignPanelTopToAnchor)
135175
}
136176
}
137177
}

Version.xcconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
APP_VERSION = 0.9.0
2-
APP_BUILD = 62
1+
APP_VERSION = 0.9.1
2+
APP_BUILD = 64

0 commit comments

Comments
 (0)