IMEStateData // Optimize kanji conversation handling.
This commit is contained in:
parent
a846022f1b
commit
6666e5ab8e
|
@ -9,13 +9,16 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct StateData {
|
public struct StateData {
|
||||||
var displayedText: String = "" {
|
var displayedText: String = ""
|
||||||
didSet {
|
var displayedTextConverted: String {
|
||||||
let result = IME.kanjiConversionIfRequired(displayedText)
|
/// 先做繁簡轉換
|
||||||
if result.utf16.count == displayedText.utf16.count, result.count == displayedText.count {
|
var result = IME.kanjiConversionIfRequired(displayedText)
|
||||||
displayedText = result
|
if result.utf16.count != displayedText.utf16.count
|
||||||
}
|
|| result.count != displayedText.count
|
||||||
|
{
|
||||||
|
result = displayedText
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Cursor & Marker & Range for UTF8
|
// MARK: Cursor & Marker & Range for UTF8
|
||||||
|
@ -86,7 +89,7 @@ public struct StateData {
|
||||||
var attributedStringNormal: NSAttributedString {
|
var attributedStringNormal: NSAttributedString {
|
||||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
||||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
||||||
let attributedString = NSMutableAttributedString(string: displayedText)
|
let attributedString = NSMutableAttributedString(string: displayedTextConverted)
|
||||||
var newBegin = 0
|
var newBegin = 0
|
||||||
for (i, neta) in displayTextSegments.enumerated() {
|
for (i, neta) in displayTextSegments.enumerated() {
|
||||||
attributedString.setAttributes(
|
attributedString.setAttributes(
|
||||||
|
@ -104,7 +107,7 @@ public struct StateData {
|
||||||
var attributedStringMarking: NSAttributedString {
|
var attributedStringMarking: NSAttributedString {
|
||||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
||||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
||||||
let attributedString = NSMutableAttributedString(string: displayedText)
|
let attributedString = NSMutableAttributedString(string: displayedTextConverted)
|
||||||
let end = u16MarkedRange.upperBound
|
let end = u16MarkedRange.upperBound
|
||||||
|
|
||||||
attributedString.setAttributes(
|
attributedString.setAttributes(
|
||||||
|
@ -130,7 +133,7 @@ public struct StateData {
|
||||||
],
|
],
|
||||||
range: NSRange(
|
range: NSRange(
|
||||||
location: end,
|
location: end,
|
||||||
length: displayedText.utf16.count - end
|
length: displayedTextConverted.utf16.count - end
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return attributedString
|
return attributedString
|
||||||
|
|
Loading…
Reference in New Issue