Skip to content

Commit

Permalink
Merge pull request #67 from mtgto/right-bug
Browse files Browse the repository at this point in the history
未確定のローマ字のみ入力時に右矢印やC-aやC-e入力でカーソルが移動しなくなるバグの修正
  • Loading branch information
mtgto authored Nov 11, 2023
2 parents 3eef26f + 9aecad7 commit 5c0cb89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 12 additions & 0 deletions macSKK/StateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ class StateMachine {
if okuri == nil { // 一度変換候補選択に遷移してからキャンセルで戻ると送り仮名ありになっている
if romaji.isEmpty {
state.inputMethod = .composing(composing.moveCursorRight())
} else if text.isEmpty {
// 未確定ローマ字しかないときは入力前に戻す (.cancelと同じ)
// AquaSKKとほぼ同じだがAquaSKKはカーソル移動も機能するのでreturn falseになってそう
state.inputMethod = .normal
} else {
state.inputMethod = .composing(ComposingState(isShift: isShift, text: text, okuri: okuri, romaji: ""))
}
Expand All @@ -504,6 +508,10 @@ class StateMachine {
if okuri == nil { // 一度変換候補選択に遷移してからキャンセルで戻ると送り仮名ありになっている
if romaji.isEmpty {
state.inputMethod = .composing(composing.moveCursorFirst())
} else if text.isEmpty {
// 未確定ローマ字しかないときは入力前に戻す (.cancelと同じ)
// AquaSKKとほぼ同じだがAquaSKKはカーソル移動も機能するのでreturn falseになってそう
state.inputMethod = .normal
} else {
// 未確定ローマ字があるときはローマ字を消す (AquaSKKと同じ)
state.inputMethod = .composing(ComposingState(isShift: isShift, text: text, okuri: okuri, romaji: ""))
Expand All @@ -515,6 +523,10 @@ class StateMachine {
if okuri == nil { // 一度変換候補選択に遷移してからキャンセルで戻ると送り仮名ありになっている
if romaji.isEmpty {
state.inputMethod = .composing(composing.moveCursorLast())
} else if text.isEmpty {
// 未確定ローマ字しかないときは入力前に戻す (.cancelと同じ)
// AquaSKKとほぼ同じだがAquaSKKはカーソル移動も機能するのでreturn falseになってそう
state.inputMethod = .normal
} else {
state.inputMethod = .composing(ComposingState(isShift: isShift, text: text, okuri: okuri, romaji: ""))
}
Expand Down
25 changes: 18 additions & 7 deletions macSKKTests/StateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1134,24 +1134,35 @@ final class StateMachineTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testHandleComposingLeftRomajiOnly() {
func testHandleComposingCursorRomajiOnly() {
let expectation = XCTestExpectation()
stateMachine.inputMethodEvent.collect(5).sink { events in
stateMachine.inputMethodEvent.collect(8).sink { events in
XCTAssertEqual(events[0], .markedText(MarkedText([.plain("k")])))
XCTAssertEqual(events[1], .markedText(MarkedText([])))
XCTAssertEqual(events[2], .markedText(MarkedText([.plain("s")])))
XCTAssertEqual(events[3], .markedText(MarkedText([.plain("sh")])))
XCTAssertEqual(events[4], .markedText(MarkedText([])))
XCTAssertEqual(events[3], .markedText(MarkedText([])))
XCTAssertEqual(events[4], .markedText(MarkedText([.plain("t")])))
XCTAssertEqual(events[5], .markedText(MarkedText([])))
XCTAssertEqual(events[6], .markedText(MarkedText([.plain("n")])))
XCTAssertEqual(events[7], .markedText(MarkedText([])))
expectation.fulfill()
}.store(in: &cancellables)
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "k")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .left, originalEvent: nil, cursorPosition: .zero)))
XCTAssertEqual(stateMachine.state.inputMethod, .normal, "ローマ字のみで左矢印キーが押されたら未入力に戻す")
XCTAssertFalse(stateMachine.handle(Action(keyEvent: .left, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "s")))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "h")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .left, originalEvent: nil, cursorPosition: .zero)))
XCTAssertEqual(stateMachine.state.inputMethod, .normal)
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .right, originalEvent: nil, cursorPosition: .zero)))
XCTAssertEqual(stateMachine.state.inputMethod, .normal, "ローマ字のみで右矢印キーが押されたら未入力に戻す")
XCTAssertFalse(stateMachine.handle(Action(keyEvent: .right, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "t")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .ctrlA, originalEvent: nil, cursorPosition: .zero)))
XCTAssertEqual(stateMachine.state.inputMethod, .normal, "ローマ字のみでCtrl-Aが押されたら未入力に戻す")
XCTAssertFalse(stateMachine.handle(Action(keyEvent: .ctrlA, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "n")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .ctrlE, originalEvent: nil, cursorPosition: .zero)))
XCTAssertEqual(stateMachine.state.inputMethod, .normal, "ローマ字のみでCtrl-Eが押されたら未入力に戻す")
XCTAssertFalse(stateMachine.handle(Action(keyEvent: .ctrlE, originalEvent: nil, cursorPosition: .zero)))
wait(for: [expectation], timeout: 1.0)
}

Expand Down

0 comments on commit 5c0cb89

Please sign in to comment.