From 9ce3c2a9e4a41e0fc5a8eaa5c05e867e6c2e39f9 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 30 Jan 2023 11:27:45 +0800 Subject: [PATCH] InputHandler // More detailed candidate revolving tooltip, etc. --- .../Modules/InputHandler_HandleStates.swift | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/Source/Modules/InputHandler_HandleStates.swift b/Source/Modules/InputHandler_HandleStates.swift index 065322e4..2e3b2bc8 100644 --- a/Source/Modules/InputHandler_HandleStates.swift +++ b/Source/Modules/InputHandler_HandleStates.swift @@ -719,35 +719,45 @@ extension InputHandler { let currentPaired = (currentNode.keyArray, currentNode.value) // 改成一次性計算,省得每次讀取時都被重複計算。 - let currentIndex: Int = { + let newIndex: Int = { + if candidates.count == 1 { return 0 } var result = 0 theLoop: for candidate in candidates { if !currentNode.isOverridden { if candidates[0] == currentPaired { result = reverseOrder ? candidates.count - 1 : 1 } break theLoop } - result = - (candidate == currentPaired && reverseOrder) - ? ((result == 0) ? candidates.count - 1 : result - 1) : result + 1 + result.revolveAsIndex(with: candidates, clockwise: !(candidate == currentPaired && reverseOrder)) if candidate == currentPaired { break } } return (0.. 1 { + consolidateNode( + candidate: candidates[newIndex], respectCursorPushing: false, + preConsolidate: false, skipObservation: true + ) } + + // 該動態函式僅用於此場合。 + 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 delegate.switchState(newState) return true