Skip to content

Commit 0c4f8ea

Browse files
committed
Recover scroll position when accepting through Accessibility API
1 parent 9f1bab9 commit 0c4f8ea

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Core/Sources/AXExtension/AXUIElement.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public extension AXUIElement {
1111
var value: String {
1212
(try? copyValue(key: kAXValueAttribute)) ?? ""
1313
}
14+
15+
var doubleValue: Double {
16+
(try? copyValue(key: kAXValueAttribute)) ?? 0.0
17+
}
1418

1519
var document: String? {
1620
try? copyValue(key: kAXDocumentAttribute)

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct PseudoCommandHandler {
9595
)) else { return }
9696

9797
let oldPosition = focusElement.selectedTextRange
98+
let oldScrollPosition = focusElement.parent?.verticalScrollBar?.doubleValue
9899

99100
let error = AXUIElementSetAttributeValue(
100101
focusElement,
@@ -130,6 +131,14 @@ struct PseudoCommandHandler {
130131
}
131132
}
132133

134+
if let oldScrollPosition, let scrollBar = focusElement.parent?.verticalScrollBar {
135+
AXUIElementSetAttributeValue(
136+
scrollBar,
137+
kAXValueAttribute as CFString,
138+
oldScrollPosition as CFTypeRef
139+
)
140+
}
141+
133142
} catch {
134143
PresentInWindowSuggestionPresenter().presentError(error)
135144
}

0 commit comments

Comments
 (0)