Skip to content

Commit 1f8710f

Browse files
committed
Run swift-format over the CandidateUI package
1 parent aac0b48 commit 1f8710f

6 files changed

Lines changed: 174 additions & 85 deletions

File tree

Packages/CandidateUI/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let package = Package(
99
products: [
1010
.library(
1111
name: "CandidateUI",
12-
targets: ["CandidateUI"]),
12+
targets: ["CandidateUI"])
1313
],
1414
dependencies: [
1515
// Dependencies declare other packages that this package depends on.

Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ public class CandidateKeyLabel: NSObject {
3838
@objc(VTCandidateControllerDelegate)
3939
public protocol CandidateControllerDelegate: AnyObject {
4040
func candidateCountForController(_ controller: CandidateController) -> UInt
41-
func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) -> String
42-
func candidateController(_ controller: CandidateController, readingAtIndex index: UInt) -> String?
43-
func candidateController(_ controller: CandidateController, requestExplanationFor candidate: String, reading: String) -> String?
44-
func candidateController(_ controller: CandidateController, didSelectCandidateAtIndex index: UInt)
41+
func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt)
42+
-> String
43+
func candidateController(_ controller: CandidateController, readingAtIndex index: UInt)
44+
-> String?
45+
func candidateController(
46+
_ controller: CandidateController, requestExplanationFor candidate: String, reading: String
47+
) -> String?
48+
func candidateController(
49+
_ controller: CandidateController, didSelectCandidateAtIndex index: UInt)
4550
}
4651

4752
@objc(VTCandidateController)
@@ -90,9 +95,10 @@ public class CandidateController: NSWindowController {
9095
}
9196
}
9297

93-
@objc public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"].map {
94-
CandidateKeyLabel(key: $0, displayedText: $0)
95-
}
98+
@objc public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
99+
.map {
100+
CandidateKeyLabel(key: $0, displayedText: $0)
101+
}
96102

97103
@objc public var keyLabelFont: NSFont = .systemFont(ofSize: 14)
98104
@objc public var candidateFont: NSFont = .systemFont(ofSize: 18)
@@ -131,9 +137,11 @@ public class CandidateController: NSWindowController {
131137
/// - height: The height that helps the window not to be out of the bottom
132138
/// of a screen.
133139
@objc(setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
134-
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
140+
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat)
141+
{
135142
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
136-
self.doSet(windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height)
143+
self.doSet(
144+
windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height)
137145
}
138146
}
139147

@@ -145,9 +153,9 @@ public class CandidateController: NSWindowController {
145153
for screen in NSScreen.screens {
146154
let frame = screen.visibleFrame
147155
if windowTopLeftPoint.x >= frame.minX,
148-
windowTopLeftPoint.x <= frame.maxX,
149-
windowTopLeftPoint.y >= frame.minY,
150-
windowTopLeftPoint.y <= frame.maxY
156+
windowTopLeftPoint.x <= frame.maxX,
157+
windowTopLeftPoint.y >= frame.minY,
158+
windowTopLeftPoint.y <= frame.maxY
151159
{
152160
screenFrame = frame
153161
break

Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import Cocoa
2525

2626
private protocol HorizontalCandidateViewDelegate: AnyObject {
27-
func view(_ view: HorizontalCandidateView, didRequestExplanationFor candidate: String, reading: String) -> String?
27+
func view(
28+
_ view: HorizontalCandidateView, didRequestExplanationFor candidate: String, reading: String
29+
) -> String?
2830
}
2931

3032
private class HorizontalCandidateView: NSView {
@@ -38,9 +40,10 @@ private class HorizontalCandidateView: NSView {
3840
let reading: String?
3941
let rect: NSRect
4042

41-
init(owner: HorizontalCandidateView, index: UInt,
42-
candidate: String, reading: String?, rect: NSRect)
43-
{
43+
init(
44+
owner: HorizontalCandidateView, index: UInt,
45+
candidate: String, reading: String?, rect: NSRect
46+
) {
4447
self.owner = owner
4548
self.index = index
4649
self.candidate = candidate
@@ -132,14 +135,17 @@ private class HorizontalCandidateView: NSView {
132135
return result
133136
}
134137

135-
func set(keyLabels labels: [String], displayedCandidates candidates: [(candidate:String, reading: String?)]) {
138+
func set(
139+
keyLabels labels: [String],
140+
displayedCandidates candidates: [(candidate: String, reading: String?)]
141+
) {
136142
let count = min(labels.count, candidates.count)
137-
keyLabels = Array(labels[0 ..< count])
138-
displayedCandidates = Array(candidates[0 ..< count])
143+
keyLabels = Array(labels[0..<count])
144+
displayedCandidates = Array(candidates[0..<count])
139145

140146
var newWidths = [CGFloat]()
141147
let baseSize = NSSize(width: 10240.0, height: 10240.0)
142-
for index in 0 ..< count {
148+
for index in 0..<count {
143149
let labelRect = (keyLabels[index] as NSString).boundingRect(
144150
with: baseSize, options: .usesLineFragmentOrigin, attributes: keyLabelAttrDict
145151
)
@@ -222,7 +228,7 @@ private class HorizontalCandidateView: NSView {
222228
}
223229

224230
var accuWidth: CGFloat = 0
225-
for index in 0 ..< elementWidths.count {
231+
for index in 0..<elementWidths.count {
226232
let currentWidth = elementWidths[index]
227233
let labelRect = NSRect(
228234
x: accuWidth, y: tooltipSize.height, width: currentWidth, height: keyLabelHeight
@@ -280,7 +286,7 @@ private class HorizontalCandidateView: NSView {
280286
return nil
281287
}
282288
var accuWidth: CGFloat = 0.0
283-
for index in 0 ..< elementWidths.count {
289+
for index in 0..<elementWidths.count {
284290
let currentWidth = elementWidths[index]
285291

286292
if location.x >= accuWidth, location.x <= accuWidth + currentWidth {
@@ -330,12 +336,13 @@ private class HorizontalCandidateView: NSView {
330336
fileprivate func buildAccessibilityChildren() {
331337
func accessibilityFrameForCandidate(at index: Int) -> NSRect {
332338
var accuWidth: CGFloat = 0
333-
for i in 0 ..< index {
339+
for i in 0..<index {
334340
accuWidth += elementWidths[i] + 1.0
335341
}
336342
let width = elementWidths[index]
337343
let height = keyLabelHeight + candidateTextHeight + 1.0
338-
let rectInView = NSRect(x: accuWidth, y: tooltipSize.height, width: width, height: height)
344+
let rectInView = NSRect(
345+
x: accuWidth, y: tooltipSize.height, width: width, height: height)
339346
return rectInView
340347
}
341348

@@ -554,7 +561,9 @@ public class HorizontalCandidateController: CandidateController {
554561
}
555562

556563
extension HorizontalCandidateController: HorizontalCandidateViewDelegate {
557-
fileprivate func view(_ view: HorizontalCandidateView, didRequestExplanationFor candidate: String, reading: String) -> String? {
564+
fileprivate func view(
565+
_ view: HorizontalCandidateView, didRequestExplanationFor candidate: String, reading: String
566+
) -> String? {
558567
delegate?.candidateController(self, requestExplanationFor: candidate, reading: reading)
559568
}
560569
}
@@ -580,12 +589,13 @@ extension HorizontalCandidateController {
580589
let keyLabelCount = UInt(keyLabels.count)
581590

582591
let begin = currentPage * keyLabelCount
583-
for index in begin ..< min(begin + keyLabelCount, count) {
592+
for index in begin..<min(begin + keyLabelCount, count) {
584593
let candidate = delegate.candidateController(self, candidateAtIndex: index)
585594
let reading = delegate.candidateController(self, readingAtIndex: index)
586595
candidates.append((candidate, reading))
587596
}
588-
candidateView.set(keyLabels: keyLabels.map { $0.displayedText }, displayedCandidates: candidates)
597+
candidateView.set(
598+
keyLabels: keyLabels.map { $0.displayedText }, displayedCandidates: candidates)
589599
candidateView.toolTip = tooltip
590600
var newSize = candidateView.sizeForView
591601
var frameRect = candidateView.frame

0 commit comments

Comments
 (0)