fix: xn→ん の変換が n+子音→ん+子音 の挙動で上書きされてしまう問題を修正

This commit is contained in:
Miwa / Ensan
2024-09-22 10:09:56 +09:00
parent 8cf7aabf63
commit fa65be47a3

View File

@@ -227,7 +227,8 @@ public struct ComposingText: Sendable {
return
}
let n_prefix = self.input[0 ..< inputCursorPosition].suffix {$0.character == "n" && $0.inputStyle == .roman2kana}
if n_prefix.count % 2 == 1 && !["n", "a", "i", "u", "e", "o", "y"].contains(first) {
if n_prefix.count % 2 == 1 && !["n", "a", "i", "u", "e", "o", "y"].contains(first)
&& self.input.dropLast(n_prefix.count).last != .init(character: "x", inputStyle: .roman2kana) {
self.input[inputCursorPosition - 1] = InputElement(character: "", inputStyle: .direct)
self.input.insert(contentsOf: string.map {InputElement(character: $0, inputStyle: inputStyle)}, at: inputCursorPosition)
return
@@ -428,12 +429,18 @@ extension ComposingText {
return true
}
let n_suffix = originalElements[0 ..< leftIndex].suffix(while: {$0.inputStyle == .roman2kana && $0.character == "n"})
// nnvalid
if n_suffix.count % 2 == 0 && !n_suffix.isEmpty {
return true
}
// nny-nnvalid
if n_suffix.count % 2 == 1 && !["a", "i", "u", "e", "o", "y", "n"].contains(firstElement.character) {
return true
}
// n1xvalid (xn)
if n_suffix.count % 2 == 1 && originalElements.dropLast(n_suffix.count).last == .init(character: "x", inputStyle: .roman2kana) {
return true
}
return false
}