diff --git a/Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift b/Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift index b90ba16c0..0f82e4ae2 100644 --- a/Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift +++ b/Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift @@ -54,7 +54,8 @@ extension ConverterServer { let userAction = UserAction.getUserAction( eventCore: request.event, inputLanguage: session.inputLanguage, - typeBackSlash: request.typeBackSlash + typeBackSlash: request.typeBackSlash, + isNumericInput: session.manager.convertTarget.last?.isNumber == true ) let (clientAction, clientActionCallback) = session.inputState.event( eventCore: request.event, diff --git a/Core/Sources/Core/InputUtils/Actions/UserAction.swift b/Core/Sources/Core/InputUtils/Actions/UserAction.swift index 58230ef21..afb53c113 100644 --- a/Core/Sources/Core/InputUtils/Actions/UserAction.swift +++ b/Core/Sources/Core/InputUtils/Actions/UserAction.swift @@ -80,7 +80,14 @@ public enum UserAction { } } - private static func intention(_ c: Character, invertPunctuation: Bool) -> Character? { + private static func intention( + _ c: Character, + invertPunctuation: Bool, + isNumericInput: Bool + ) -> Character? { + if c == ".", isNumericInput, !invertPunctuation { + return c + } switch c { case ",": let normal: Character = switch Config.PunctuationStyle().value { @@ -110,7 +117,8 @@ public enum UserAction { public static func getUserAction( eventCore: KeyEventCore, inputLanguage: InputLanguage, - typeBackSlash: Bool? = nil + typeBackSlash: Bool? = nil, + isNumericInput: Bool = false ) -> UserAction { let typeBackSlash = typeBackSlash ?? Config.TypeBackSlash().value // see: https://developer.mozilla.org/ja/docs/Web/API/UI_Events/Keyboard_event_code_values#mac_%E3%81%A7%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%E5%80%A4 @@ -120,7 +128,15 @@ public enum UserAction { return string.map { .character($0) } case .japanese: return string.map { - .key(intention: intention($0, invertPunctuation: invertPunctuation), input: $0, modifiers: []) + .key( + intention: intention( + $0, + invertPunctuation: invertPunctuation, + isNumericInput: isNumericInput + ), + input: $0, + modifiers: [] + ) } } } diff --git a/Core/Tests/CoreTests/InputUtilsTests/UserActionOptionPunctuationTests.swift b/Core/Tests/CoreTests/InputUtilsTests/UserActionOptionPunctuationTests.swift index eabb78664..807c32224 100644 --- a/Core/Tests/CoreTests/InputUtilsTests/UserActionOptionPunctuationTests.swift +++ b/Core/Tests/CoreTests/InputUtilsTests/UserActionOptionPunctuationTests.swift @@ -64,6 +64,26 @@ private func makeEvent( eventCore: makeEvent(logicalKey: ".", characters: "≥", modifiers: option), inputLanguage: .japanese )) == "。") + for (style, normal, inverted): (Config.PunctuationStyle.Value, String, String) in [ + (.kutenAndToten, "。", "."), + (.kutenAndComma, "。", "."), + (.periodAndToten, ".", "。"), + (.periodAndComma, ".", "。") + ] { + Config.PunctuationStyle().value = style + for isNumericInput in [false, true] { + #expect(inputString(from: UserAction.getUserAction( + eventCore: makeEvent(logicalKey: ".", characters: ".", modifiers: []), + inputLanguage: .japanese, + isNumericInput: isNumericInput + )) == (isNumericInput ? "." : normal)) + #expect(inputString(from: UserAction.getUserAction( + eventCore: makeEvent(logicalKey: ".", characters: "≥", modifiers: option), + inputLanguage: .japanese, + isNumericInput: isNumericInput + )) == inverted) + } + } #expect(inputString(from: UserAction.getUserAction( eventCore: makeEvent(logicalKey: "[", characters: "[", modifiers: option),