IMEState // Remove useless variables, etc.
* Also reordering certain variables.
This commit is contained in:
parent
b1f256ef05
commit
7d776baed5
|
@ -21,7 +21,6 @@ public protocol IMEStateProtocol {
|
||||||
var textToCommit: String { get set }
|
var textToCommit: String { get set }
|
||||||
var tooltip: String { get set }
|
var tooltip: String { get set }
|
||||||
var tooltipDuration: Double { get set }
|
var tooltipDuration: Double { get set }
|
||||||
var attributedString: NSAttributedString { get }
|
|
||||||
var convertedToInputting: IMEStateProtocol { get }
|
var convertedToInputting: IMEStateProtocol { get }
|
||||||
var isFilterable: Bool { get }
|
var isFilterable: Bool { get }
|
||||||
var isMarkedLengthValid: Bool { get }
|
var isMarkedLengthValid: Bool { get }
|
||||||
|
@ -53,9 +52,6 @@ public protocol IMEStateDataProtocol {
|
||||||
var tooltipBackupForInputting: String { get set }
|
var tooltipBackupForInputting: String { get set }
|
||||||
var tooltip: String { get set }
|
var tooltip: String { get set }
|
||||||
var tooltipDuration: Double { get set }
|
var tooltipDuration: Double { get set }
|
||||||
var attributedStringNormal: NSAttributedString { get }
|
|
||||||
var attributedStringMarking: NSAttributedString { get }
|
|
||||||
var attributedStringPlaceholder: NSAttributedString { get }
|
|
||||||
var userPhraseKVPair: (keyArray: [String], value: String) { get }
|
var userPhraseKVPair: (keyArray: [String], value: String) { get }
|
||||||
var tooltipColorState: TooltipColorState { get set }
|
var tooltipColorState: TooltipColorState { get set }
|
||||||
mutating func updateTooltipForMarking()
|
mutating func updateTooltipForMarking()
|
||||||
|
|
|
@ -190,14 +190,6 @@ public extension IMEState {
|
||||||
set { data.tooltip = newValue }
|
set { data.tooltip = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
var attributedString: NSAttributedString {
|
|
||||||
switch type {
|
|
||||||
case .ofMarking: return data.attributedStringMarking
|
|
||||||
case .ofAssociates, .ofSymbolTable: return data.attributedStringPlaceholder
|
|
||||||
default: return data.attributedStringNormal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func attributedString(for session: IMKInputController) -> NSAttributedString {
|
func attributedString(for session: IMKInputController) -> NSAttributedString {
|
||||||
switch type {
|
switch type {
|
||||||
case .ofMarking: return data.attributedStringMarking(for: session)
|
case .ofMarking: return data.attributedStringMarking(for: session)
|
||||||
|
|
|
@ -95,16 +95,6 @@ public struct IMEStateData: IMEStateDataProtocol {
|
||||||
public var markedReadings = [String]()
|
public var markedReadings = [String]()
|
||||||
public var candidates = [(keyArray: [String], value: String)]()
|
public var candidates = [(keyArray: [String], value: String)]()
|
||||||
public var textToCommit: String = ""
|
public var textToCommit: String = ""
|
||||||
public var tooltip: String = ""
|
|
||||||
public var tooltipDuration: Double = 1.0
|
|
||||||
public var tooltipBackupForInputting: String = ""
|
|
||||||
public var attributedStringPlaceholder: NSAttributedString = .init(
|
|
||||||
string: " ",
|
|
||||||
attributes: [
|
|
||||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
|
||||||
.markedClauseSegment: 0,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
public var isFilterable: Bool {
|
public var isFilterable: Bool {
|
||||||
guard isMarkedLengthValid else { return false } // 範圍長度必須合規。
|
guard isMarkedLengthValid else { return false } // 範圍長度必須合規。
|
||||||
|
@ -118,60 +108,12 @@ public struct IMEStateData: IMEStateDataProtocol {
|
||||||
Self.allowedMarkLengthRange.contains(markedRange.count)
|
Self.allowedMarkLengthRange.contains(markedRange.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Tooltip neta.
|
||||||
|
|
||||||
|
public var tooltip: String = ""
|
||||||
|
public var tooltipDuration: Double = 1.0
|
||||||
|
public var tooltipBackupForInputting: String = ""
|
||||||
public var tooltipColorState: TooltipColorState = .normal
|
public var tooltipColorState: TooltipColorState = .normal
|
||||||
|
|
||||||
public var attributedStringNormal: NSAttributedString {
|
|
||||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
|
||||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
|
||||||
let attributedString = NSMutableAttributedString(string: displayedTextConverted)
|
|
||||||
var newBegin = 0
|
|
||||||
for (i, neta) in displayTextSegments.enumerated() {
|
|
||||||
attributedString.setAttributes(
|
|
||||||
[
|
|
||||||
/// 不能用 .thick,否則會看不到游標。
|
|
||||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
|
||||||
.markedClauseSegment: i,
|
|
||||||
], range: NSRange(location: newBegin, length: neta.utf16.count)
|
|
||||||
)
|
|
||||||
newBegin += neta.utf16.count
|
|
||||||
}
|
|
||||||
return attributedString
|
|
||||||
}
|
|
||||||
|
|
||||||
public var attributedStringMarking: NSAttributedString {
|
|
||||||
/// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況,
|
|
||||||
/// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。
|
|
||||||
let attributedString = NSMutableAttributedString(string: displayedTextConverted)
|
|
||||||
let end = u16MarkedRange.upperBound
|
|
||||||
|
|
||||||
attributedString.setAttributes(
|
|
||||||
[
|
|
||||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
|
||||||
.markedClauseSegment: 0,
|
|
||||||
], range: NSRange(location: 0, length: u16MarkedRange.lowerBound)
|
|
||||||
)
|
|
||||||
attributedString.setAttributes(
|
|
||||||
[
|
|
||||||
.underlineStyle: NSUnderlineStyle.thick.rawValue,
|
|
||||||
.markedClauseSegment: 1,
|
|
||||||
],
|
|
||||||
range: NSRange(
|
|
||||||
location: u16MarkedRange.lowerBound,
|
|
||||||
length: u16MarkedRange.upperBound - u16MarkedRange.lowerBound
|
|
||||||
)
|
|
||||||
)
|
|
||||||
attributedString.setAttributes(
|
|
||||||
[
|
|
||||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
|
||||||
.markedClauseSegment: 2,
|
|
||||||
],
|
|
||||||
range: NSRange(
|
|
||||||
location: end,
|
|
||||||
length: displayedTextConverted.utf16.count - end
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return attributedString
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - AttributedString 生成器
|
// MARK: - AttributedString 生成器
|
||||||
|
|
Loading…
Reference in New Issue