InputHandler // Implement Alt+Delete/BackSpace behavior.
This commit is contained in:
parent
4c0445115b
commit
9256866f2c
|
@ -202,6 +202,16 @@ public class InputHandler: InputHandlerProtocol {
|
||||||
return arrResult
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
/// 鞏固當前組字器游標上下文,防止在當前游標位置固化節點時給作業範圍以外的內容帶來不想要的變化。
|
/// 鞏固當前組字器游標上下文,防止在當前游標位置固化節點時給作業範圍以外的內容帶來不想要的變化。
|
||||||
///
|
///
|
||||||
/// 打比方說輸入法原廠詞庫內有「章太炎」一詞,你敲「章太炎」,然後想把「太」改成「泰」以使其變成「章泰炎」。
|
/// 打比方說輸入法原廠詞庫內有「章太炎」一詞,你敲「章太炎」,然後想把「太」改成「泰」以使其變成「章泰炎」。
|
||||||
|
|
|
@ -438,24 +438,32 @@ extension InputHandler {
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.isShiftHold, input.isOptionHold {
|
let steps = getStepsToNearbyNodeBorder(direction: .rear)
|
||||||
|
var actualSteps = 1
|
||||||
|
|
||||||
|
switch input.modifierFlags {
|
||||||
|
case .shift:
|
||||||
delegate.switchState(IMEState.ofAbortion())
|
delegate.switchState(IMEState.ofAbortion())
|
||||||
return true
|
return true
|
||||||
|
case .option:
|
||||||
|
actualSteps = steps
|
||||||
|
default: break
|
||||||
}
|
}
|
||||||
|
|
||||||
if isComposerOrCalligrapherEmpty {
|
if isComposerOrCalligrapherEmpty {
|
||||||
if compositor.cursor > 0 {
|
if compositor.cursor <= 0 || actualSteps <= 0 {
|
||||||
compositor.dropKey(direction: .rear)
|
|
||||||
walk()
|
|
||||||
} else {
|
|
||||||
delegate.callError("9D69908D")
|
delegate.callError("9D69908D")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
for _ in 0 ..< actualSteps {
|
||||||
|
compositor.dropKey(direction: .rear)
|
||||||
|
}
|
||||||
|
walk()
|
||||||
} else {
|
} else {
|
||||||
letComposerAndCalligrapherDoBackSpace()
|
letComposerAndCalligrapherDoBackSpace()
|
||||||
}
|
}
|
||||||
|
|
||||||
switch isComposerOrCalligrapherEmpty && compositor.isEmpty {
|
switch isConsideredEmptyForNow {
|
||||||
case false: delegate.switchState(generateStateOfInputting())
|
case false: delegate.switchState(generateStateOfInputting())
|
||||||
case true: delegate.switchState(IMEState.ofAbortion())
|
case true: delegate.switchState(IMEState.ofAbortion())
|
||||||
}
|
}
|
||||||
|
@ -477,18 +485,28 @@ extension InputHandler {
|
||||||
|
|
||||||
guard state.type == .ofInputting else { return false }
|
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())
|
delegate.switchState(IMEState.ofAbortion())
|
||||||
return true
|
return true
|
||||||
}
|
case _ where !input.isShiftHold && input.isOptionHold && !input.isControlHold:
|
||||||
|
actualSteps = steps
|
||||||
if compositor.cursor == compositor.length, isComposerOrCalligrapherEmpty {
|
default: break
|
||||||
delegate.callError("9B69938D")
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isComposerOrCalligrapherEmpty {
|
if isComposerOrCalligrapherEmpty {
|
||||||
|
if compositor.cursor >= compositor.length || actualSteps <= 0 {
|
||||||
|
delegate.callError("9B69938D")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _ in 0 ..< actualSteps {
|
||||||
compositor.dropKey(direction: .front)
|
compositor.dropKey(direction: .front)
|
||||||
|
}
|
||||||
walk()
|
walk()
|
||||||
} else {
|
} else {
|
||||||
clearComposerAndCalligrapher()
|
clearComposerAndCalligrapher()
|
||||||
|
|
Loading…
Reference in New Issue