SessionCtl // Simplify handle(state).

This commit is contained in:
ShikiSuen 2022-10-11 00:00:58 +08:00
parent 1e8b0af44b
commit 458e7fa613
2 changed files with 10 additions and 14 deletions

View File

@ -40,8 +40,12 @@ extension SessionCtl {
return lineHeightRect return lineHeightRect
} }
public func show(tooltip: String) { public func showTooltip(_ tooltip: String) {
guard client() != nil else { return } guard client() != nil else { return }
if tooltip.isEmpty {
tooltipInstance.hide()
return
}
let lineHeightRect = lineHeightRect() let lineHeightRect = lineHeightRect()
var finalOrigin: NSPoint = lineHeightRect.origin var finalOrigin: NSPoint = lineHeightRect.origin
let delta: Double = lineHeightRect.size.height + 4.0 // bottomOutOfScreenAdjustmentHeight let delta: Double = lineHeightRect.size.height + 4.0 // bottomOutOfScreenAdjustmentHeight

View File

@ -66,28 +66,20 @@ extension SessionCtl {
case .ofCommitting: case .ofCommitting:
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
tooltipInstance.hide() tooltipInstance.hide()
let textToCommit = newState.textToCommit commit(text: newState.textToCommit)
if !textToCommit.isEmpty { commit(text: textToCommit) }
clearInlineDisplay() clearInlineDisplay()
// //
keyHandler.clear() keyHandler.clear()
case .ofInputting: case .ofInputting:
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
tooltipInstance.hide() tooltipInstance.hide()
let textToCommit = newState.textToCommit commit(text: newState.textToCommit)
if !textToCommit.isEmpty { commit(text: textToCommit) }
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
if !newState.tooltip.isEmpty { showTooltip(newState.tooltip)
show(tooltip: newState.tooltip)
}
case .ofMarking: case .ofMarking:
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
if newState.tooltip.isEmpty { showTooltip(newState.tooltip)
tooltipInstance.hide()
} else {
show(tooltip: newState.tooltip)
}
case .ofCandidates, .ofAssociates, .ofSymbolTable: case .ofCandidates, .ofAssociates, .ofSymbolTable:
tooltipInstance.hide() tooltipInstance.hide()
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
@ -142,7 +134,7 @@ extension SessionCtl {
/// ///
/// IMK commitComposition /// IMK commitComposition
private func commit(text: String) { private func commit(text: String) {
guard let client = client() else { return } guard let client = client(), !text.isEmpty else { return }
let buffer = ChineseConverter.kanjiConversionIfRequired(text) let buffer = ChineseConverter.kanjiConversionIfRequired(text)
if buffer.isEmpty { if buffer.isEmpty {
return return