Skip to content

Commit 16ba72e

Browse files
committed
Support making widget stay inside editor when the editor is wide enough
1 parent 5beec87 commit 16ba72e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Core/Sources/SuggestionWidget/WidgetPositionStrategy.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ enum UpdateLocationStrategy {
8080
tabFrame: CGRect,
8181
alignPanelTopToAnchor: Bool
8282
) {
83+
let preferredInsideEditorMinWidth = 1400 as Double
84+
8385
let maxY = max(
8486
y,
8587
mainScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
@@ -101,7 +103,10 @@ enum UpdateLocationStrategy {
101103

102104
let proposedPanelX = proposedAnchorFrameOnTheRightSide.maxX + Style
103105
.widgetPadding * 2
104-
let putPanelToTheRight = activeScreen.frame.maxX > proposedPanelX + Style.panelWidth
106+
let putPanelToTheRight = {
107+
if editorFrame.size.width >= preferredInsideEditorMinWidth { return false }
108+
return activeScreen.frame.maxX > proposedPanelX + Style.panelWidth
109+
}()
105110
let alignPanelTopToAnchor = fixedAlignment ?? (y > activeScreen.frame.midY)
106111

107112
if putPanelToTheRight {
@@ -132,7 +137,14 @@ enum UpdateLocationStrategy {
132137
)
133138
let proposedPanelX = proposedAnchorFrameOnTheLeftSide.minX - Style
134139
.widgetPadding * 2 - Style.panelWidth
135-
let putAnchorToTheLeft = proposedPanelX > activeScreen.frame.minX
140+
let putAnchorToTheLeft = {
141+
if editorFrame.size.width >= preferredInsideEditorMinWidth {
142+
if editorFrame.maxX <= activeScreen.frame.maxX {
143+
return false
144+
}
145+
}
146+
return proposedPanelX > activeScreen.frame.minX
147+
}()
136148

137149
if putAnchorToTheLeft {
138150
let anchorFrame = proposedAnchorFrameOnTheLeftSide

0 commit comments

Comments
 (0)