Skip to content

Commit

Permalink
Merge pull request #548 from zonble/master
Browse files Browse the repository at this point in the history
Fixes the crash that happens while handling the tab key.
  • Loading branch information
lukhnos committed Oct 22, 2024
2 parents 593c6b4 + 84dd949 commit 59eb438
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions McBopomofoTests/KeyHandlerBopomofoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion Source/KeyHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 59eb438

Please sign in to comment.