Skip to content

Commit 1b6e9a6

Browse files
committed
feat: Enable accessibility for the vertical candidate window
This commit extends the accessibility improvements to the vertical candidate window, ensuring it is fully accessible to assistive technologies like VoiceOver. - Implements NSAccessibility protocols for the vertical candidate view. - Exposes each candidate in the vertical list as an individual accessibility element. - Ensures VoiceOver can correctly read and navigate the candidates. - Posts notifications when the selection changes. Fixes openvanilla#657
1 parent 4009146 commit 1b6e9a6

3 files changed

Lines changed: 206 additions & 119 deletions

File tree

Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public class CandidateController: NSWindowController {
4949
reloadData()
5050
}
5151
}
52-
@objc public var selectedCandidateIndex: UInt = UInt.max
52+
53+
@objc public var selectedCandidateIndex: UInt = .max
5354
@objc public var visible: Bool = false {
5455
didSet {
5556
NSObject.cancelPreviousPerformRequests(withTarget: self)
@@ -69,6 +70,7 @@ public class CandidateController: NSWindowController {
6970
}
7071
}
7172
}
73+
7274
@objc public var windowTopLeftPoint: NSPoint {
7375
get {
7476
guard let frameRect = window?.frame else {
@@ -86,12 +88,12 @@ public class CandidateController: NSWindowController {
8688
@objc public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"].map {
8789
CandidateKeyLabel(key: $0, displayedText: $0)
8890
}
89-
@objc public var keyLabelFont: NSFont = NSFont.systemFont(ofSize: 14)
90-
@objc public var candidateFont: NSFont = NSFont.systemFont(ofSize: 18)
91+
92+
@objc public var keyLabelFont: NSFont = .systemFont(ofSize: 14)
93+
@objc public var candidateFont: NSFont = .systemFont(ofSize: 18)
9194
@objc public var tooltip: String = ""
9295

93-
@objc public func reloadData() {
94-
}
96+
@objc public func reloadData() {}
9597

9698
@objc public func showNextPage() -> Bool {
9799
false
@@ -109,7 +111,7 @@ public class CandidateController: NSWindowController {
109111
false
110112
}
111113

112-
@objc public func candidateIndexAtKeyLabelIndex(_ index: UInt) -> UInt {
114+
@objc public func candidateIndexAtKeyLabelIndex(_: UInt) -> UInt {
113115
UInt.max
114116
}
115117

@@ -137,10 +139,11 @@ public class CandidateController: NSWindowController {
137139
var screenFrame = NSScreen.main?.visibleFrame ?? NSRect.zero
138140
for screen in NSScreen.screens {
139141
let frame = screen.visibleFrame
140-
if windowTopLeftPoint.x >= frame.minX &&
141-
windowTopLeftPoint.x <= frame.maxX &&
142-
windowTopLeftPoint.y >= frame.minY &&
143-
windowTopLeftPoint.y <= frame.maxY {
142+
if windowTopLeftPoint.x >= frame.minX,
143+
windowTopLeftPoint.x <= frame.maxX,
144+
windowTopLeftPoint.y >= frame.minY,
145+
windowTopLeftPoint.y <= frame.maxY
146+
{
144147
screenFrame = frame
145148
break
146149
}
@@ -174,5 +177,4 @@ public class CandidateController: NSWindowController {
174177

175178
window?.setFrameTopLeftPoint(adjustedPoint)
176179
}
177-
178180
}

0 commit comments

Comments
 (0)