Skip to content

Commit

Permalink
単語登録画面でタブキーで入力文字列を補完する
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgto committed Jan 1, 2024
1 parent e1dfdef commit b7c9566
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions macSKK/Assets.xcassets/icon-sougou.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"filename" : "icon-sougou.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions macSKK/StateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class StateMachine {
}
return true
case .tab:
if case .register(let registerState) = state.specialState {
state.inputMethod = .composing(registerState.prev.composing)
updateMarkedText()
return true
}
return false
case .stickyShift:
switch state.inputMode {
Expand Down
32 changes: 32 additions & 0 deletions macSKKTests/StateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,38 @@ final class StateMachineTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testHandleRegisteringTab() {
let expectation = XCTestExpectation()
stateMachine.inputMethodEvent.collect(12).sink { events in
XCTAssertEqual(events[0], .markedText(MarkedText([.markerCompose, .plain("")])))
XCTAssertEqual(events[1], .markedText(MarkedText([.markerCompose, .plain("あい")])))
XCTAssertEqual(events[2], .modeChanged(.hiragana, .zero))
XCTAssertEqual(events[3], .markedText(MarkedText([.plain("[登録:あい]")])))
// 単語登録で空文字列のときにTabキーを押すと単語登録までの読みが補完される
XCTAssertEqual(events[4], .markedText(MarkedText([.plain("[登録:あい]"), .markerCompose, .plain("あい")])))
XCTAssertEqual(events[5], .markedText(MarkedText([.plain("[登録:あい]"), .markerCompose, .plain("")])))
XCTAssertEqual(events[6], .markedText(MarkedText([.plain("[登録:あい]")])))
XCTAssertEqual(events[7], .markedText(MarkedText([.markerCompose, .plain("あい")])))
XCTAssertEqual(events[8], .markedText(MarkedText([.markerCompose, .plain("あい*k")])))
XCTAssertEqual(events[9], .modeChanged(.hiragana, .zero))
XCTAssertEqual(events[10], .markedText(MarkedText([.plain("[登録:あい*く]")])))
XCTAssertEqual(events[11], .markedText(MarkedText([.plain("[登録:あい*く]"), .markerCompose, .plain("あい*く")])))
expectation.fulfill()
}.store(in: &cancellables)
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "a", withShift: true)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "i")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .space, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .tab, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .tab, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .backspace, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .cancel, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .cancel, originalEvent: nil, cursorPosition: .zero)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "k", withShift: true)))
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "u")))
XCTAssertTrue(stateMachine.handle(Action(keyEvent: .tab, originalEvent: nil, cursorPosition: .zero)))
wait(for: [expectation], timeout: 1.0)
}

func testHandleSelectingEnter() {
dictionary.setEntries(["": [Word("")]])

Expand Down

0 comments on commit b7c9566

Please sign in to comment.