diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/IMEStateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/IMEStateProtocol.swift index 905598bd..4a7d411f 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/IMEStateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/IMEStateProtocol.swift @@ -21,7 +21,6 @@ public protocol IMEStateProtocol { var textToCommit: String { get set } var tooltip: String { get set } var tooltipDuration: Double { get set } - var attributedString: NSAttributedString { get } var convertedToInputting: IMEStateProtocol { get } var isFilterable: Bool { get } var isMarkedLengthValid: Bool { get } @@ -53,9 +52,6 @@ public protocol IMEStateDataProtocol { var tooltipBackupForInputting: String { get set } var tooltip: String { 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 tooltipColorState: TooltipColorState { get set } mutating func updateTooltipForMarking() diff --git a/Source/Modules/IMEState.swift b/Source/Modules/IMEState.swift index 9df32025..88d905d3 100644 --- a/Source/Modules/IMEState.swift +++ b/Source/Modules/IMEState.swift @@ -190,14 +190,6 @@ public extension IMEState { 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 { switch type { case .ofMarking: return data.attributedStringMarking(for: session) diff --git a/Source/Modules/IMEStateData.swift b/Source/Modules/IMEStateData.swift index b6019d36..875e8c2f 100644 --- a/Source/Modules/IMEStateData.swift +++ b/Source/Modules/IMEStateData.swift @@ -95,16 +95,6 @@ public struct IMEStateData: IMEStateDataProtocol { public var markedReadings = [String]() public var candidates = [(keyArray: [String], value: 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 { guard isMarkedLengthValid else { return false } // 範圍長度必須合規。 @@ -118,60 +108,12 @@ public struct IMEStateData: IMEStateDataProtocol { 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 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 生成器