Skip to content

Commit c9fe778

Browse files
committed
Fix vertical candidate window flickering
The flickering issue is more often found with the vertical candidate window, likely due to the layout passes it needs to go through. This PR makes sure that candidate window position is first set before the window becomes visible. This PR also switches to use dispatch queue for all delayed method invocation. This makes sure that all such deferred actions are put in the same queue, and so they will be performed in the expected order.
1 parent 60a759b commit c9fe778

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ public class CandidateController: NSWindowController {
6161
}
6262
let alreadyVisible = window.isVisible
6363
if visible {
64-
window.perform(#selector(NSWindow.orderFront(_:)), with: self, afterDelay: 0.0)
64+
DispatchQueue.main.async {
65+
window.orderFront(self)
66+
}
6567
if !alreadyVisible {
6668
NSAccessibility.post(element: window, notification: .created)
6769
NSAccessibility
6870
.post(element: window, notification: .focusedWindowChanged)
6971
}
7072
} else {
71-
window.perform(#selector(NSWindow.orderOut(_:)), with: self, afterDelay: 0.0)
73+
DispatchQueue.main.async {
74+
window.orderOut(self)
75+
}
7276
}
7377
}
7478
}

Source/InputMethodController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,6 @@ extension McBopomofoInputMethodController {
799799
gCurrentCandidateController?.reloadData()
800800
currentClient = client
801801

802-
gCurrentCandidateController?.visible = true
803-
804802
var lineHeightRect = NSMakeRect(0.0, 0.0, 16.0, 16.0)
805803
var cursor: Int = 0
806804

@@ -829,6 +827,8 @@ extension McBopomofoInputMethodController {
829827
lineHeightRect.origin.x, lineHeightRect.origin.y - 4.0),
830828
bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0)
831829
}
830+
831+
gCurrentCandidateController?.visible = true
832832
}
833833

834834
private func show(tooltip: String, composingBuffer: String, cursorIndex: UInt, client: Any!) {

0 commit comments

Comments
 (0)