InputHandler // Implement Alt+Delete/BackSpace behavior.

This commit is contained in:
ShikiSuen 2023-02-13 19:26:37 +08:00
parent 4c0445115b
commit 9256866f2c
2 changed files with 41 additions and 13 deletions

View File

@ -202,6 +202,16 @@ public class InputHandler: InputHandlerProtocol {
return arrResult
}
///
/// - Parameter direction:
/// - Returns:
func getStepsToNearbyNodeBorder(direction: Megrez.Compositor.TypingDirection) -> Int {
let currentCursor = compositor.cursor
var testCompositor = compositor
testCompositor.jumpCursorBySpan(to: direction)
return abs(testCompositor.cursor - currentCursor)
}
///
///
/// 使

View File

@ -438,24 +438,32 @@ extension InputHandler {
default: break
}
if input.isShiftHold, input.isOptionHold {
let steps = getStepsToNearbyNodeBorder(direction: .rear)
var actualSteps = 1
switch input.modifierFlags {
case .shift:
delegate.switchState(IMEState.ofAbortion())
return true
case .option:
actualSteps = steps
default: break
}
if isComposerOrCalligrapherEmpty {
if compositor.cursor > 0 {
compositor.dropKey(direction: .rear)
walk()
} else {
if compositor.cursor <= 0 || actualSteps <= 0 {
delegate.callError("9D69908D")
return true
}
for _ in 0 ..< actualSteps {
compositor.dropKey(direction: .rear)
}
walk()
} else {
letComposerAndCalligrapherDoBackSpace()
}
switch isComposerOrCalligrapherEmpty && compositor.isEmpty {
switch isConsideredEmptyForNow {
case false: delegate.switchState(generateStateOfInputting())
case true: delegate.switchState(IMEState.ofAbortion())
}
@ -477,18 +485,28 @@ extension InputHandler {
guard state.type == .ofInputting else { return false }
if input.isShiftHold {
let steps = getStepsToNearbyNodeBorder(direction: .front)
var actualSteps = 1
// macOS PC Delete .function
//
switch input.modifierFlags {
case _ where input.isShiftHold && !input.isOptionHold && !input.isControlHold:
delegate.switchState(IMEState.ofAbortion())
return true
}
if compositor.cursor == compositor.length, isComposerOrCalligrapherEmpty {
delegate.callError("9B69938D")
return true
case _ where !input.isShiftHold && input.isOptionHold && !input.isControlHold:
actualSteps = steps
default: break
}
if isComposerOrCalligrapherEmpty {
compositor.dropKey(direction: .front)
if compositor.cursor >= compositor.length || actualSteps <= 0 {
delegate.callError("9B69938D")
return true
}
for _ in 0 ..< actualSteps {
compositor.dropKey(direction: .front)
}
walk()
} else {
clearComposerAndCalligrapher()