mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
Merge pull request #226 from azooKey/fix/composing_count_equatable
fix: `ComposingCount`の比較を容易にするため、カスタムの`Equatable`適合を追加
This commit is contained in:
@@ -67,7 +67,7 @@ public enum CompleteAction: Equatable, Sendable {
|
|||||||
case moveCursor(Int)
|
case moveCursor(Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ComposingCount: Equatable, Sendable {
|
public enum ComposingCount: Sendable, Equatable {
|
||||||
/// composingText.inputにおいて対応する文字数。
|
/// composingText.inputにおいて対応する文字数。
|
||||||
case inputCount(Int)
|
case inputCount(Int)
|
||||||
/// composingText.convertTargeにおいて対応する文字数。
|
/// composingText.convertTargeにおいて対応する文字数。
|
||||||
@@ -86,6 +86,55 @@ public enum ComposingCount: Equatable, Sendable {
|
|||||||
.composite(lhs: lhs, rhs: rhs)
|
.composite(lhs: lhs, rhs: rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct FlatComposingCount: Equatable {
|
||||||
|
enum Kind {
|
||||||
|
case inputCount
|
||||||
|
case surfaceCount
|
||||||
|
}
|
||||||
|
var kind: Kind
|
||||||
|
var value: Int
|
||||||
|
static func inputCount(_ value: Int) -> Self {
|
||||||
|
.init(kind: .inputCount, value: value)
|
||||||
|
}
|
||||||
|
static func surfaceCount(_ value: Int) -> Self {
|
||||||
|
.init(kind: .surfaceCount, value: value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var flatten: [FlatComposingCount] {
|
||||||
|
switch self {
|
||||||
|
case .inputCount(let value):
|
||||||
|
if value == 0 {
|
||||||
|
[]
|
||||||
|
} else {
|
||||||
|
[.inputCount(value)]
|
||||||
|
}
|
||||||
|
case .surfaceCount(let value):
|
||||||
|
if value == 0 {
|
||||||
|
[]
|
||||||
|
} else {
|
||||||
|
[.surfaceCount(value)]
|
||||||
|
}
|
||||||
|
case .composite(let lhs, let rhs):
|
||||||
|
{
|
||||||
|
let lFlatten = lhs.flatten
|
||||||
|
let rFlatten = rhs.flatten
|
||||||
|
return switch (lFlatten.last?.kind, rFlatten.first?.kind) {
|
||||||
|
case (.inputCount, .inputCount):
|
||||||
|
lFlatten.dropLast() + [.inputCount(lFlatten.last!.value + rFlatten.first!.value)] + rFlatten.dropFirst()
|
||||||
|
case (.surfaceCount, .surfaceCount):
|
||||||
|
lFlatten.dropLast() + [.surfaceCount(lFlatten.last!.value + rFlatten.first!.value)] + rFlatten.dropFirst()
|
||||||
|
default:
|
||||||
|
lFlatten + rFlatten
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func == (lhs: Self, rhs: Self) -> Bool {
|
||||||
|
lhs.flatten == rhs.flatten
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 変換候補のデータ
|
/// 変換候補のデータ
|
||||||
|
|||||||
Reference in New Issue
Block a user