InputHandler // More detailed candidate revolving tooltip, etc.
This commit is contained in:
parent
fc32da5bb9
commit
9ce3c2a9e4
|
@ -719,35 +719,45 @@ extension InputHandler {
|
||||||
let currentPaired = (currentNode.keyArray, currentNode.value)
|
let currentPaired = (currentNode.keyArray, currentNode.value)
|
||||||
|
|
||||||
// 改成一次性計算,省得每次讀取時都被重複計算。
|
// 改成一次性計算,省得每次讀取時都被重複計算。
|
||||||
let currentIndex: Int = {
|
let newIndex: Int = {
|
||||||
|
if candidates.count == 1 { return 0 }
|
||||||
var result = 0
|
var result = 0
|
||||||
theLoop: for candidate in candidates {
|
theLoop: for candidate in candidates {
|
||||||
if !currentNode.isOverridden {
|
if !currentNode.isOverridden {
|
||||||
if candidates[0] == currentPaired { result = reverseOrder ? candidates.count - 1 : 1 }
|
if candidates[0] == currentPaired { result = reverseOrder ? candidates.count - 1 : 1 }
|
||||||
break theLoop
|
break theLoop
|
||||||
}
|
}
|
||||||
result =
|
result.revolveAsIndex(with: candidates, clockwise: !(candidate == currentPaired && reverseOrder))
|
||||||
(candidate == currentPaired && reverseOrder)
|
|
||||||
? ((result == 0) ? candidates.count - 1 : result - 1) : result + 1
|
|
||||||
if candidate == currentPaired { break }
|
if candidate == currentPaired { break }
|
||||||
}
|
}
|
||||||
return (0..<candidates.count).contains(result) ? result : 0
|
return (0..<candidates.count).contains(result) ? result : 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
consolidateNode(
|
if candidates.count > 1 {
|
||||||
candidate: candidates[currentIndex], respectCursorPushing: false,
|
consolidateNode(
|
||||||
preConsolidate: false, skipObservation: true
|
candidate: candidates[newIndex], respectCursorPushing: false,
|
||||||
)
|
preConsolidate: false, skipObservation: true
|
||||||
delegate.updateVerticalTypingStatus()
|
)
|
||||||
var newState = generateStateOfInputting()
|
|
||||||
newState.tooltip = (currentIndex + 1).description + " / " + candidates.count.description + " "
|
|
||||||
vCLog(newState.tooltip)
|
|
||||||
if #available(macOS 10.13, *) {
|
|
||||||
if delegate.isVerticalTyping, Bundle.main.preferredLocalizations[0] != "en" {
|
|
||||||
let locID = Bundle.main.preferredLocalizations[0]
|
|
||||||
newState.tooltip = (currentIndex + 1).i18n(loc: locID) + "・" + candidates.count.i18n(loc: locID) + ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 該動態函式僅用於此場合。
|
||||||
|
func isContextVertical() -> Bool {
|
||||||
|
delegate.updateVerticalTypingStatus()
|
||||||
|
return delegate.isVerticalTyping
|
||||||
|
}
|
||||||
|
|
||||||
|
var newState = generateStateOfInputting()
|
||||||
|
let locID = Bundle.main.preferredLocalizations[0]
|
||||||
|
let newTooltip = NSMutableString()
|
||||||
|
newTooltip.insert(" " + candidates[newIndex].1, at: 0)
|
||||||
|
if #available(macOS 10.13, *), isContextVertical(), locID != "en" {
|
||||||
|
newTooltip.insert((newIndex + 1).i18n(loc: locID) + "・" + candidates.count.i18n(loc: locID), at: 0)
|
||||||
|
} else {
|
||||||
|
newTooltip.insert((newIndex + 1).description + " / " + candidates.count.description, at: 0)
|
||||||
|
}
|
||||||
|
newTooltip.append(" ")
|
||||||
|
newState.tooltip = newTooltip.description
|
||||||
|
vCLog(newState.tooltip)
|
||||||
newState.tooltipDuration = 0
|
newState.tooltipDuration = 0
|
||||||
delegate.switchState(newState)
|
delegate.switchState(newState)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue