Repo // Remove the useless .ofNotEmpty() state.

This commit is contained in:
ShikiSuen 2022-10-30 14:16:06 +08:00
parent 71aafba1c5
commit 47ab4867b1
3 changed files with 72 additions and 63 deletions

View File

@ -123,17 +123,33 @@ public enum TooltipColorState {
// MARK: - IMEState types.
// enum
/// enum
public enum StateType: String {
/// ** .ofDeactivated**: 使使使
case ofDeactivated = "Deactivated"
/// ** .ofEmpty**: 使
///
/// /
/// 使
///
case ofEmpty = "Empty"
case ofAbortion = "Abortion" // Empty
/// ** .ofAbortion**: .ofEmpty()
/// .ofEmpty()
case ofAbortion = "Abortion"
/// ** .ofCommitting**:
/// .ofEmpty()
/// .ofEmpty()
case ofCommitting = "Committing"
/// ** .ofAssociates**:
case ofAssociates = "Associates"
case ofNotEmpty = "NotEmpty"
/// ** .ofInputting**: 使Compositor
case ofInputting = "Inputting"
/// ** .ofMarking**: 使
///
case ofMarking = "Marking"
/// ** .ofCandidates**: 使
case ofCandidates = "Candidates"
/// ** .ofSymbolTable**:
case ofSymbolTable = "SymbolTable"
}

View File

@ -26,20 +26,23 @@ import Shared
///
///
///
/// - .Deactivated: 使使
/// - .AssociatedPhrases:
/// 西 .NotEmpty
/// - .Empty: 使
///
/// - .Abortion: Empty
/// .Empty()
/// - .Committing:
/// - .NotEmpty:
/// - .Inputting: 使Compositor
/// - .Marking: 使
///
/// - .ChoosingCandidate: 使
/// - .SymbolTable:
/// - ** .ofDeactivated**: 使使使
/// - ** .ofEmpty**: 使
///
/// /
/// 使
///
/// - ** .ofAssociates**:
/// - ** .ofAbortion**: .ofEmpty()
/// .ofEmpty()
/// - ** .ofCommitting**:
/// .ofEmpty()
/// .ofEmpty()
/// - ** .ofInputting**: 使Compositor
/// - ** .ofMarking**: 使
///
/// - ** .ofCandidates**: 使
/// - ** .ofSymbolTable**:
public struct IMEState: IMEStateProtocol {
public var type: StateType = .ofEmpty
public var data: IMEStateDataProtocol = IMEStateData() as IMEStateDataProtocol
@ -52,6 +55,28 @@ public struct IMEState: IMEStateProtocol {
isVerticalTyping = SessionCtl.isVerticalTyping
}
///
/// - Parameters:
/// - displayTextSegments:
/// - cursor: UTF8
fileprivate init(displayTextSegments: [String], cursor: Int) {
// displayTextSegments
data.displayTextSegments = displayTextSegments.map {
if !SessionCtl.isVerticalTyping { return $0 }
guard PrefMgr.shared.hardenVerticalPunctuations else { return $0 }
var neta = $0
ChineseConverter.hardenVerticalPunctuations(target: &neta, convert: SessionCtl.isVerticalTyping)
return neta
}
data.cursor = cursor
data.marker = cursor
}
///
/// - Parameters:
/// - data:
/// - type:
/// - node:
init(
_ data: IMEStateDataProtocol = IMEStateData() as IMEStateDataProtocol, type: StateType = .ofEmpty,
node: CandidateNode
@ -88,24 +113,8 @@ extension IMEState {
return result
}
public static func ofNotEmpty(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = IMEState(type: .ofNotEmpty)
// displayTextSegments
result.data.displayTextSegments = displayTextSegments.map {
if !SessionCtl.isVerticalTyping { return $0 }
guard PrefMgr.shared.hardenVerticalPunctuations else { return $0 }
var neta = $0
ChineseConverter.hardenVerticalPunctuations(target: &neta, convert: SessionCtl.isVerticalTyping)
return neta
}
result.data.cursor = cursor
result.data.marker = cursor
return result
}
public static func ofInputting(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
var result = IMEState(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofInputting
return result
}
@ -115,7 +124,7 @@ extension IMEState {
)
-> IMEState
{
var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
var result = IMEState(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofMarking
result.data.marker = marker
result.data.markedReadings = markedReadings
@ -126,14 +135,14 @@ extension IMEState {
public static func ofCandidates(candidates: [(String, String)], displayTextSegments: [String], cursor: Int)
-> IMEState
{
var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
var result = IMEState(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofCandidates
result.data.candidates = candidates
return result
}
public static func ofSymbolTable(node: CandidateNode) -> IMEState {
var result = IMEState(type: .ofNotEmpty, node: node)
var result = IMEState(node: node)
result.type = .ofSymbolTable
return result
}
@ -195,7 +204,7 @@ extension IMEState {
/// InputHandler 使 !compositor.isEmpty
public var hasComposition: Bool {
switch type {
case .ofNotEmpty, .ofInputting, .ofMarking, .ofCandidates: return true
case .ofInputting, .ofMarking, .ofCandidates: return true
default: return false
}
}

View File

@ -95,7 +95,6 @@ extension SessionCtl {
tooltipInstance.hide()
setInlineDisplayWithCursor()
showCandidates()
default: break
}
//
if newState.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) {
@ -108,33 +107,18 @@ extension SessionCtl {
}
}
/// .NotEmpty()
/// /
public func setInlineDisplayWithCursor() {
if state.type == .ofAssociates {
doSetMarkedText(
state.data.attributedStringPlaceholder, selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
)
return
}
if state.hasComposition || state.isCandidateContainer {
/// selectionRange
/// 0 replacementRangeNSNotFound
///
doSetMarkedText(
attributedStringSecured.0, selectionRange: attributedStringSecured.1,
replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
)
return
}
//
clearInlineDisplay()
/// selectionRange
/// 0 replacementRangeNSNotFound
///
doSetMarkedText(
attributedStringSecured.0, selectionRange: attributedStringSecured.1,
replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
)
}
/// .NotEmpty()
/// setInlineDisplayWithCursor()
/// 使
private func clearInlineDisplay() {
doSetMarkedText(
"", selectionRange: NSRange(location: 0, length: 0),