Repo // Let tooltip window auto-disappear after given seconds.
This commit is contained in:
parent
751824feef
commit
4e124e6aac
|
@ -53,7 +53,7 @@ public class TooltipUI: NSWindowController {
|
|||
public func show(
|
||||
tooltip: String = "", at point: NSPoint,
|
||||
bottomOutOfScreenAdjustmentHeight heightDelta: Double,
|
||||
direction: NSAttributedTooltipTextView.writingDirection = .horizontal
|
||||
direction: NSAttributedTooltipTextView.writingDirection = .horizontal, duration: Double = 0
|
||||
) {
|
||||
self.direction = direction
|
||||
self.tooltip = tooltip
|
||||
|
@ -61,6 +61,11 @@ public class TooltipUI: NSWindowController {
|
|||
window?.orderFront(nil)
|
||||
set(windowTopLeftPoint: point, bottomOutOfScreenAdjustmentHeight: heightDelta, useGCD: false)
|
||||
window?.setIsVisible(true)
|
||||
if duration > 0 {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
|
||||
self.window?.orderOut(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func setColor(state: TooltipColorState) {
|
||||
|
|
|
@ -40,7 +40,7 @@ extension SessionCtl {
|
|||
return lineHeightRect
|
||||
}
|
||||
|
||||
public func showTooltip(_ tooltip: String) {
|
||||
public func showTooltip(_ tooltip: String, duration: Double = 0) {
|
||||
guard client() != nil else { return }
|
||||
if tooltip.isEmpty {
|
||||
tooltipInstance.hide()
|
||||
|
@ -66,8 +66,8 @@ extension SessionCtl {
|
|||
}
|
||||
// 再設定其文字顯示內容並顯示。
|
||||
tooltipInstance.show(
|
||||
tooltip: tooltip, at: finalOrigin,
|
||||
bottomOutOfScreenAdjustmentHeight: delta, direction: tooltipContentDirection
|
||||
tooltip: tooltip, at: finalOrigin, bottomOutOfScreenAdjustmentHeight: delta,
|
||||
direction: tooltipContentDirection, duration: duration
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ extension SessionCtl {
|
|||
if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) {
|
||||
commit(text: previous.displayedText)
|
||||
}
|
||||
showTooltip(newState.tooltip) // 會在工具提示為空的時候自動消除顯示。
|
||||
showTooltip(newState.tooltip, duration: 1) // 會在工具提示為空的時候自動消除顯示。
|
||||
clearInlineDisplay()
|
||||
// 最後一道保險
|
||||
inputHandler.clear()
|
||||
|
@ -84,7 +84,7 @@ extension SessionCtl {
|
|||
ctlCandidateCurrent.visible = false
|
||||
commit(text: newState.textToCommit)
|
||||
setInlineDisplayWithCursor()
|
||||
showTooltip(newState.tooltip) // 會在工具提示為空的時候自動消除顯示。
|
||||
showTooltip(newState.tooltip, duration: 1) // 會在工具提示為空的時候自動消除顯示。
|
||||
case .ofMarking:
|
||||
ctlCandidateCurrent.visible = false
|
||||
setInlineDisplayWithCursor()
|
||||
|
|
Loading…
Reference in New Issue