Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Core/Sources/Core/InputUtils/InputState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public enum InputState: Sendable, Hashable {
case .escape:
return (.stopComposition, .transition(.none))
case .space:
if liveConversionEnabled {
if inputLanguage == .english {
return (.appendToMarkedText(" "), .fallthrough)
} else if liveConversionEnabled {
return (.enterCandidateSelectionMode, .transition(.selecting))
} else {
return (.enterFirstCandidatePreviewMode, .transition(.previewing))
Expand Down
84 changes: 84 additions & 0 deletions Core/Tests/CoreTests/InputUtilsTests/InputStateSpaceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import Core
import Foundation
import KanaKanjiConverterModule
import Testing

private let spaceEvent = KeyEventCore(
modifierFlags: [],
characters: " ",
charactersIgnoringModifiers: " ",
keyCode: 49
)

@Suite("InputState space key behavior in composing state")
struct InputStateSpaceTests {
@Test func spaceInEnglishComposingAppendsSpace() {
let (action, _) = InputState.composing.event(
eventCore: spaceEvent,
userAction: .space(prefersFullWidthWhenInput: false),
inputLanguage: .english,
liveConversionEnabled: false,
enableDebugWindow: false,
enableSuggestion: false
)
guard case .appendToMarkedText(let text) = action else {
Issue.record("Expected appendToMarkedText, got \(action)")
return
}
#expect(text == " ")
}

@Test func spaceInEnglishComposingAppendsSpaceEvenWithLiveConversion() {
let (action, _) = InputState.composing.event(
eventCore: spaceEvent,
userAction: .space(prefersFullWidthWhenInput: false),
inputLanguage: .english,
liveConversionEnabled: true,
enableDebugWindow: false,
enableSuggestion: false
)
guard case .appendToMarkedText(let text) = action else {
Issue.record("Expected appendToMarkedText, got \(action)")
return
}
#expect(text == " ")
}

@Test func spaceInJapaneseComposingWithLiveConversionEntersCandidateSelection() {
let (action, callback) = InputState.composing.event(
eventCore: spaceEvent,
userAction: .space(prefersFullWidthWhenInput: false),
inputLanguage: .japanese,
liveConversionEnabled: true,
enableDebugWindow: false,
enableSuggestion: false
)
guard case .enterCandidateSelectionMode = action else {
Issue.record("Expected enterCandidateSelectionMode, got \(action)")
return
}
guard case .transition(.selecting) = callback else {
Issue.record("Expected transition(.selecting), got \(callback)")
return
}
}

@Test func spaceInJapaneseComposingWithoutLiveConversionEntersPreview() {
let (action, callback) = InputState.composing.event(
eventCore: spaceEvent,
userAction: .space(prefersFullWidthWhenInput: false),
inputLanguage: .japanese,
liveConversionEnabled: false,
enableDebugWindow: false,
enableSuggestion: false
)
guard case .enterFirstCandidatePreviewMode = action else {
Issue.record("Expected enterFirstCandidatePreviewMode, got \(action)")
return
}
guard case .transition(.previewing) = callback else {
Issue.record("Expected transition(.previewing), got \(callback)")
return
}
}
}
Loading