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
3 changes: 2 additions & 1 deletion Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 19 additions & 3 deletions Core/Sources/Core/InputUtils/Actions/UserAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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: []
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down