diff --git a/McBopomofoTests/KeyHandlerBopomofoTests.swift b/McBopomofoTests/KeyHandlerBopomofoTests.swift index ece3a095..b093de02 100644 --- a/McBopomofoTests/KeyHandlerBopomofoTests.swift +++ b/McBopomofoTests/KeyHandlerBopomofoTests.swift @@ -1811,6 +1811,44 @@ class KeyHandlerBopomofoTests: XCTestCase { XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)") } + func testMacroAndTabKey() { + // zonble + var state: InputState = InputState.Empty() + // 今天 + let keys = Array("rup wu0 ").map { + String($0) + } + for key in keys { + let input = KeyHandlerInput( + inputText: key, keyCode: 0, charCode: charCode(key), flags: [], + isVerticalMode: false) + handler.handle(input: input, state: state) { newState in + state = newState + } errorCallback: { + } + } + let input = KeyHandlerInput( + inputText: " ", keyCode: KeyCode.tab.rawValue, charCode: 0, flags: [], + isVerticalMode: false) + + handler.handle(input: input, state: state) { newState in + state = newState + } errorCallback: { + } + + handler.handle(input: input, state: state) { newState in + state = newState + } errorCallback: { + } + + handler.handle(input: input, state: state) { newState in + state = newState + } errorCallback: { + } + + NSLog("\(state)") + } + func testLookUpCandidateInDictionaryAndCancelWithTabKey() { var state: InputState = InputState.Empty() let keys = Array("wu0 dj/ ").map { diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index f042af15..c4ebeb22 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -830,7 +830,8 @@ - (BOOL)_handleTabState:(InputState *)state shiftIsHold:(BOOL)shiftIsHold stateC } InputStateCandidate *candidate = candidates[currentIndex]; - [self fixNodeWithReading:candidate.reading value:candidate.value originalCursorIndex:candidateState.originalCursorIndex useMoveCursorAfterSelectionSetting:NO]; + size_t originalCursorIndex = _grid->cursor(); + [self fixNodeWithReading:candidate.reading value:candidate.value originalCursorIndex:originalCursorIndex useMoveCursorAfterSelectionSetting:NO]; InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); return YES;