From 7591447c8e22781308e547f812927e994b7b49cb Mon Sep 17 00:00:00 2001 From: mtgto Date: Thu, 9 Nov 2023 23:52:02 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9C=AA=E7=A2=BA=E5=AE=9A=E3=81=AE?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=9E=E5=AD=97=E3=81=AE=E3=81=BF=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E6=99=82=E3=81=AB=E5=8F=B3=E7=9F=A2=E5=8D=B0=E3=82=AD?= =?UTF-8?q?=E3=83=BC=E3=81=8C=E5=85=A5=E5=8A=9B=E3=81=95=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E3=82=89=E6=9C=AA=E5=85=A5=E5=8A=9B=E7=8A=B6=E6=85=8B=E3=81=AB?= =?UTF-8?q?=E6=88=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macSKK/StateMachine.swift | 4 ++++ macSKKTests/StateMachineTests.swift | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/macSKK/StateMachine.swift b/macSKK/StateMachine.swift index 70abc094..cb495675 100644 --- a/macSKK/StateMachine.swift +++ b/macSKK/StateMachine.swift @@ -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: "")) } diff --git a/macSKKTests/StateMachineTests.swift b/macSKKTests/StateMachineTests.swift index 9534a736..3c9f56ff 100644 --- a/macSKKTests/StateMachineTests.swift +++ b/macSKKTests/StateMachineTests.swift @@ -1155,6 +1155,27 @@ final class StateMachineTests: XCTestCase { wait(for: [expectation], timeout: 1.0) } + func testHandleComposingRightRomajiOnly() { + let expectation = XCTestExpectation() + stateMachine.inputMethodEvent.collect(5).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([]))) + expectation.fulfill() + }.store(in: &cancellables) + XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "k"))) + 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: "s"))) + XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "h"))) + XCTAssertTrue(stateMachine.handle(Action(keyEvent: .right, originalEvent: nil, cursorPosition: .zero))) + XCTAssertEqual(stateMachine.state.inputMethod, .normal) + wait(for: [expectation], timeout: 1.0) + } + func testHandleComposingLeftOkuri() { dictionary.setEntries(["あs": [Word("褪")]]) From 8a0e319d67b495697bf2f03b5c30efb44f290cce Mon Sep 17 00:00:00 2001 From: mtgto Date: Thu, 9 Nov 2023 23:58:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9C=AA=E7=A2=BA=E5=AE=9A=E3=81=AE?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=9E=E5=AD=97=E3=81=AE=E3=81=BF=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E6=99=82=E3=81=ABC-a,=20C-e=E3=81=8C=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E3=81=95=E3=82=8C=E3=81=9F=E3=82=89=E6=9C=AA=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E7=8A=B6=E6=85=8B=E3=81=AB=E6=88=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macSKK/StateMachine.swift | 8 ++++++++ macSKKTests/StateMachineTests.swift | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/macSKK/StateMachine.swift b/macSKK/StateMachine.swift index cb495675..b07862ea 100644 --- a/macSKK/StateMachine.swift +++ b/macSKK/StateMachine.swift @@ -508,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: "")) @@ -519,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: "")) } diff --git a/macSKKTests/StateMachineTests.swift b/macSKKTests/StateMachineTests.swift index 3c9f56ff..5dbf02c6 100644 --- a/macSKKTests/StateMachineTests.swift +++ b/macSKKTests/StateMachineTests.swift @@ -1155,14 +1155,15 @@ final class StateMachineTests: XCTestCase { wait(for: [expectation], timeout: 1.0) } - func testHandleComposingRightRomajiOnly() { + func testHandleComposingRomajiOnly() { let expectation = XCTestExpectation() - stateMachine.inputMethodEvent.collect(5).sink { events in + stateMachine.inputMethodEvent.collect(6).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([]))) expectation.fulfill() }.store(in: &cancellables) XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "k"))) @@ -1170,9 +1171,13 @@ final class StateMachineTests: XCTestCase { XCTAssertEqual(stateMachine.state.inputMethod, .normal, "ローマ字のみで右矢印キーが押されたら未入力に戻す") XCTAssertFalse(stateMachine.handle(Action(keyEvent: .right, originalEvent: nil, cursorPosition: .zero))) XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "s"))) - XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "h"))) - XCTAssertTrue(stateMachine.handle(Action(keyEvent: .right, originalEvent: nil, cursorPosition: .zero))) - XCTAssertEqual(stateMachine.state.inputMethod, .normal) + 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: "t"))) + 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) } From 9aecad7436ed44b37d156664a2811e9a1952221a Mon Sep 17 00:00:00 2001 From: mtgto Date: Sat, 11 Nov 2023 21:17:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=81=BB=E3=81=BC=E5=90=8C=E3=81=98?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?1=E3=81=A4=E3=81=AB=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macSKKTests/StateMachineTests.swift | 33 ++++++++--------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/macSKKTests/StateMachineTests.swift b/macSKKTests/StateMachineTests.swift index 5dbf02c6..8764a448 100644 --- a/macSKKTests/StateMachineTests.swift +++ b/macSKKTests/StateMachineTests.swift @@ -1134,14 +1134,17 @@ 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"))) @@ -1149,32 +1152,14 @@ final class StateMachineTests: XCTestCase { 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) - wait(for: [expectation], timeout: 1.0) - } - - func testHandleComposingRomajiOnly() { - let expectation = XCTestExpectation() - stateMachine.inputMethodEvent.collect(6).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([]))) - XCTAssertEqual(events[4], .markedText(MarkedText([.plain("t")]))) - XCTAssertEqual(events[5], .markedText(MarkedText([]))) - expectation.fulfill() - }.store(in: &cancellables) - XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "k"))) 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: "s"))) + 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: "t"))) + 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)))