InputHandler // Properly handle arrow keys for certain submodes.

This commit is contained in:
ShikiSuen 2023-08-11 16:18:55 +08:00
parent 4a476e0a50
commit b375da5c95
3 changed files with 21 additions and 10 deletions

View File

@ -31,7 +31,7 @@ public protocol InputHandlerProtocol {
func ensureKeyboardParser() func ensureKeyboardParser()
func triageInput(event input: InputSignalProtocol) -> Bool func triageInput(event input: InputSignalProtocol) -> Bool
func generateStateOfCandidates() -> IMEStateProtocol func generateStateOfCandidates() -> IMEStateProtocol
func generateStateOfInputting(sansReading: Bool) -> IMEStateProtocol func generateStateOfInputting(sansReading: Bool, guarded: Bool) -> IMEStateProtocol
func generateStateOfAssociates(withPair pair: Megrez.KeyValuePaired) -> IMEStateProtocol func generateStateOfAssociates(withPair pair: Megrez.KeyValuePaired) -> IMEStateProtocol
func consolidateNode( func consolidateNode(
candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool, skipObservation: Bool candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool, skipObservation: Bool
@ -41,8 +41,8 @@ public protocol InputHandlerProtocol {
} }
extension InputHandlerProtocol { extension InputHandlerProtocol {
func generateStateOfInputting(sansReading: Bool = false) -> IMEStateProtocol { func generateStateOfInputting(sansReading: Bool = false, guarded: Bool = false) -> IMEStateProtocol {
generateStateOfInputting(sansReading: sansReading) generateStateOfInputting(sansReading: sansReading, guarded: guarded)
} }
func consolidateNode(candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool) { func consolidateNode(candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool) {

View File

@ -391,7 +391,7 @@ extension InputHandler {
case 0 ..< 4: case 0 ..< 4:
if strCodePointBuffer.count < 3 { if strCodePointBuffer.count < 3 {
strCodePointBuffer.append(input.text) strCodePointBuffer.append(input.text)
var updatedState = generateStateOfInputting() var updatedState = generateStateOfInputting(guarded: true)
updatedState.tooltipDuration = 0 updatedState.tooltipDuration = 0
updatedState.tooltip = tooltipCodePointInputMode updatedState.tooltip = tooltipCodePointInputMode
delegate.switchState(updatedState) delegate.switchState(updatedState)
@ -418,7 +418,8 @@ extension InputHandler {
} }
// macOS // macOS
if char.count > 1 { char = char.map(\.description)[0] } if char.count > 1 { char = char.map(\.description)[0] }
var updatedState = IMEState.ofCommitting(textToCommit: char) delegate.switchState(IMEState.ofCommitting(textToCommit: char))
var updatedState = generateStateOfInputting(guarded: true)
updatedState.tooltipDuration = 0 updatedState.tooltipDuration = 0
updatedState.tooltip = tooltipCodePointInputMode updatedState.tooltip = tooltipCodePointInputMode
delegate.switchState(updatedState) delegate.switchState(updatedState)

View File

@ -18,8 +18,12 @@ extension InputHandler {
// MARK: - State Building // MARK: - State Building
/// ///
public func generateStateOfInputting(sansReading: Bool = false) -> IMEStateProtocol { /// - Parameters:
if isConsideredEmptyForNow { return IMEState.ofAbortion() } /// - sansReading: /
/// - guarded: InputMethodKit
/// - Returns:
public func generateStateOfInputting(sansReading: Bool = false, guarded: Bool = false) -> IMEStateProtocol {
if isConsideredEmptyForNow, !guarded { return IMEState.ofAbortion() }
var segHighlightedAt: Int? var segHighlightedAt: Int?
let cpInput = isCodePointInputMode && !sansReading let cpInput = isCodePointInputMode && !sansReading
/// (Update the composing buffer) /// (Update the composing buffer)
@ -68,6 +72,12 @@ extension InputHandler {
cursor: cursor, highlightAt: segHighlightedAt cursor: cursor, highlightAt: segHighlightedAt
) )
result.marker = cursorSansReading result.marker = cursorSansReading
///
if guarded, result.displayTextSegments.joined().isEmpty {
result.data.displayTextSegments = [" "]
result.cursor = 0
result.marker = 0
}
return result return result
} }
@ -440,7 +450,7 @@ extension InputHandler {
if isCodePointInputMode { if isCodePointInputMode {
if !strCodePointBuffer.isEmpty { if !strCodePointBuffer.isEmpty {
func refreshState() { func refreshState() {
var updatedState = generateStateOfInputting() var updatedState = generateStateOfInputting(guarded: true)
updatedState.tooltipDuration = 0 updatedState.tooltipDuration = 0
updatedState.tooltip = tooltipCodePointInputMode updatedState.tooltip = tooltipCodePointInputMode
delegate.switchState(updatedState) delegate.switchState(updatedState)
@ -895,7 +905,7 @@ extension InputHandler {
} }
var updatedState = generateStateOfInputting(sansReading: true) var updatedState = generateStateOfInputting(sansReading: true)
delegate.switchState(IMEState.ofCommitting(textToCommit: updatedState.displayedText)) delegate.switchState(IMEState.ofCommitting(textToCommit: updatedState.displayedText))
updatedState = IMEState.ofEmpty() updatedState = generateStateOfInputting(guarded: true)
updatedState.tooltipDuration = 0 updatedState.tooltipDuration = 0
updatedState.tooltip = tooltipCodePointInputMode updatedState.tooltip = tooltipCodePointInputMode
delegate.switchState(updatedState) delegate.switchState(updatedState)
@ -915,7 +925,7 @@ extension InputHandler {
} }
var updatedState = generateStateOfInputting(sansReading: true) var updatedState = generateStateOfInputting(sansReading: true)
delegate.switchState(IMEState.ofCommitting(textToCommit: updatedState.displayedText)) delegate.switchState(IMEState.ofCommitting(textToCommit: updatedState.displayedText))
updatedState = IMEState.ofEmpty() updatedState = generateStateOfInputting(guarded: true)
updatedState.tooltipDuration = 0 updatedState.tooltipDuration = 0
updatedState.tooltip = Self.tooltipHaninKeyboardSymbolMode updatedState.tooltip = Self.tooltipHaninKeyboardSymbolMode
delegate.switchState(updatedState) delegate.switchState(updatedState)