Skip to content

Commit fc92767

Browse files
Naoki Takahashiclaude
andcommitted
fix: 英語composing状態でスペースキーを押した場合に半角空白を入力する
closes #248 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eb3e4e5 commit fc92767

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

Core/Sources/Core/InputUtils/InputState.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public enum InputState: Sendable, Hashable {
140140
case .escape:
141141
return (.stopComposition, .transition(.none))
142142
case .space:
143-
if liveConversionEnabled {
143+
if inputLanguage == .english {
144+
return (.appendToMarkedText(" "), .fallthrough)
145+
} else if liveConversionEnabled {
144146
return (.enterCandidateSelectionMode, .transition(.selecting))
145147
} else {
146148
return (.enterFirstCandidatePreviewMode, .transition(.previewing))
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import Core
2+
import Foundation
3+
import KanaKanjiConverterModule
4+
import Testing
5+
6+
private let spaceEvent = KeyEventCore(
7+
modifierFlags: [],
8+
characters: " ",
9+
charactersIgnoringModifiers: " ",
10+
keyCode: 49
11+
)
12+
13+
@Suite("InputState space key behavior in composing state")
14+
struct InputStateSpaceTests {
15+
@Test func spaceInEnglishComposingAppendsSpace() {
16+
let (action, _) = InputState.composing.event(
17+
eventCore: spaceEvent,
18+
userAction: .space(prefersFullWidthWhenInput: false),
19+
inputLanguage: .english,
20+
liveConversionEnabled: false,
21+
enableDebugWindow: false,
22+
enableSuggestion: false
23+
)
24+
guard case .appendToMarkedText(let text) = action else {
25+
Issue.record("Expected appendToMarkedText, got \(action)")
26+
return
27+
}
28+
#expect(text == " ")
29+
}
30+
31+
@Test func spaceInEnglishComposingAppendsSpaceEvenWithLiveConversion() {
32+
let (action, _) = InputState.composing.event(
33+
eventCore: spaceEvent,
34+
userAction: .space(prefersFullWidthWhenInput: false),
35+
inputLanguage: .english,
36+
liveConversionEnabled: true,
37+
enableDebugWindow: false,
38+
enableSuggestion: false
39+
)
40+
guard case .appendToMarkedText(let text) = action else {
41+
Issue.record("Expected appendToMarkedText, got \(action)")
42+
return
43+
}
44+
#expect(text == " ")
45+
}
46+
47+
@Test func spaceInJapaneseComposingWithLiveConversionEntersCandidateSelection() {
48+
let (action, callback) = InputState.composing.event(
49+
eventCore: spaceEvent,
50+
userAction: .space(prefersFullWidthWhenInput: false),
51+
inputLanguage: .japanese,
52+
liveConversionEnabled: true,
53+
enableDebugWindow: false,
54+
enableSuggestion: false
55+
)
56+
guard case .enterCandidateSelectionMode = action else {
57+
Issue.record("Expected enterCandidateSelectionMode, got \(action)")
58+
return
59+
}
60+
guard case .transition(.selecting) = callback else {
61+
Issue.record("Expected transition(.selecting), got \(callback)")
62+
return
63+
}
64+
}
65+
66+
@Test func spaceInJapaneseComposingWithoutLiveConversionEntersPreview() {
67+
let (action, callback) = InputState.composing.event(
68+
eventCore: spaceEvent,
69+
userAction: .space(prefersFullWidthWhenInput: false),
70+
inputLanguage: .japanese,
71+
liveConversionEnabled: false,
72+
enableDebugWindow: false,
73+
enableSuggestion: false
74+
)
75+
guard case .enterFirstCandidatePreviewMode = action else {
76+
Issue.record("Expected enterFirstCandidatePreviewMode, got \(action)")
77+
return
78+
}
79+
guard case .transition(.previewing) = callback else {
80+
Issue.record("Expected transition(.previewing), got \(callback)")
81+
return
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)