SessionCtl // Cope with `%quick` candidates.

This commit is contained in:
ShikiSuen 2023-06-14 11:11:24 +08:00
parent e771654a2f
commit b0c2bfc54e
9 changed files with 67 additions and 31 deletions

View File

@ -84,6 +84,12 @@ extension SessionCtl: CtlCandidateDelegate {
let blankResult: [String] = [] let blankResult: [String] = []
// //
if !PrefMgr.shared.showReverseLookupInCandidateUI { return blankResult } if !PrefMgr.shared.showReverseLookupInCandidateUI { return blankResult }
if state.type == .ofInputting, state.isCandidateContainer,
inputHandler?.currentLM.nullCandidateInCassette == value
{
return blankResult
}
if !PrefMgr.shared.showReverseLookupInCandidateUI { return blankResult }
if isVerticalTyping { return blankResult } // if isVerticalTyping { return blankResult } //
if value.isEmpty { return blankResult } // 西 if value.isEmpty { return blankResult } // 西
if value.contains("_") { return blankResult } if value.contains("_") { return blankResult }
@ -92,7 +98,17 @@ extension SessionCtl: CtlCandidateDelegate {
} }
public var selectionKeys: String { public var selectionKeys: String {
PrefMgr.shared.useIMKCandidateWindow ? "123456789" : PrefMgr.shared.candidateKeys // `%quick` 1234567890
if state.type == .ofInputting, state.isCandidateContainer {
guard let cinCandidateKey = LMMgr.currentLM.cassetteSelectionKey,
CandidateKey.validate(keys: cinCandidateKey) == nil
else {
return "1234567890"
}
return cinCandidateKey
}
if PrefMgr.shared.useIMKCandidateWindow { return "123456789" }
return PrefMgr.shared.candidateKeys
} }
public func candidatePairs(conv: Bool = false) -> [(keyArray: [String], value: String)] { public func candidatePairs(conv: Bool = false) -> [(keyArray: [String], value: String)] {
@ -114,6 +130,7 @@ extension SessionCtl: CtlCandidateDelegate {
public func candidatePairSelectionConfirmed(at index: Int) { public func candidatePairSelectionConfirmed(at index: Int) {
guard let inputHandler = inputHandler else { return } guard let inputHandler = inputHandler else { return }
guard state.isCandidateContainer else { return }
switch state.type { switch state.type {
case .ofSymbolTable where (0 ..< state.node.members.count).contains(index): case .ofSymbolTable where (0 ..< state.node.members.count).contains(index):
let node = state.node.members[index] let node = state.node.members[index]
@ -124,12 +141,10 @@ extension SessionCtl: CtlCandidateDelegate {
} }
case .ofCandidates where (0 ..< state.candidates.count).contains(index): case .ofCandidates where (0 ..< state.candidates.count).contains(index):
let selectedValue = state.candidates[index] let selectedValue = state.candidates[index]
if state.type == .ofCandidates { inputHandler.consolidateNode(
inputHandler.consolidateNode( candidate: selectedValue, respectCursorPushing: true,
candidate: selectedValue, respectCursorPushing: true, preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection
preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection )
)
}
var result: IMEStateProtocol = inputHandler.generateStateOfInputting() var result: IMEStateProtocol = inputHandler.generateStateOfInputting()
defer { switchState(result) } // defer { switchState(result) } //
if PrefMgr.shared.useSCPCTypingMode { if PrefMgr.shared.useSCPCTypingMode {
@ -157,6 +172,14 @@ extension SessionCtl: CtlCandidateDelegate {
withPair: .init(keyArray: selectedValue.keyArray, value: valueKept) withPair: .init(keyArray: selectedValue.keyArray, value: valueKept)
) )
if !associates.candidates.isEmpty { result = associates } if !associates.candidates.isEmpty { result = associates }
case .ofInputting where (0 ..< state.candidates.count).contains(index):
let chosenStr = state.candidates[index].value
guard !chosenStr.isEmpty, chosenStr != inputHandler.currentLM.nullCandidateInCassette else {
callError("907F9F64")
return
}
let strToCommitFirst = inputHandler.generateStateOfInputting(sansReading: true).displayedText
switchState(IMEState.ofCommitting(textToCommit: strToCommitFirst + chosenStr))
default: return default: return
} }
} }

View File

@ -84,35 +84,33 @@ public extension SessionCtl {
? .vertical ? .vertical
: .horizontal) : .horizontal)
let isInputtingWithCandidates = state.type == .ofInputting && state.isCandidateContainer
/// NSWindow() /// NSWindow()
candidateUI?.visible = false candidateUI?.visible = false
///
if #available(macOS 10.13, *) { if #available(macOS 10.13, *) {
candidateUI = ///
PrefMgr.shared.useIMKCandidateWindow let useIMK = PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout) candidateUI = useIMK ? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
if let candidateTDK = candidateUI as? CtlCandidateTDK {
let singleLine = isVerticalTyping || PrefMgr.shared.candidateWindowShowOnlyOneLine
candidateTDK.maxLinesPerPage = singleLine ? 1 : 4
}
} else { } else {
candidateUI = CtlCandidateTDK(candidateLayout) candidateUI = CtlCandidateTDK(candidateLayout)
} }
var singleLine = isVerticalTyping || PrefMgr.shared.candidateWindowShowOnlyOneLine
singleLine = singleLine || isInputtingWithCandidates
(candidateUI as? CtlCandidateTDK)?.maxLinesPerPage = singleLine ? 1 : 4
candidateUI?.candidateFont = Self.candidateFont( candidateUI?.candidateFont = Self.candidateFont(
name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize
) )
let singleColumn = isVerticalTyping || PrefMgr.shared.candidateWindowShowOnlyOneLine
if PrefMgr.shared.cassetteEnabled {
candidateUI?.tooltip =
singleColumn ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "")
}
if state.type == .ofAssociates { if state.type == .ofAssociates {
candidateUI?.tooltip = candidateUI?.tooltip =
singleColumn ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "") singleLine ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
} else if state.type == .ofInputting, state.isCandidateContainer {
candidateUI?.tooltip =
singleLine ? "⚡️" : "⚡️ " + NSLocalizedString("Quick Candidates", comment: "")
} else if PrefMgr.shared.cassetteEnabled {
candidateUI?.tooltip =
singleLine ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "")
} }
candidateUI?.locale = { candidateUI?.locale = {

View File

@ -75,6 +75,7 @@ public extension SessionCtl {
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
// //
showTooltip(newState.tooltip, duration: newState.tooltipDuration) showTooltip(newState.tooltip, duration: newState.tooltipDuration)
if newState.isCandidateContainer { showCandidates() }
case .ofMarking: case .ofMarking:
candidateUI?.visible = false candidateUI?.visible = false
setInlineDisplayWithCursor() setInlineDisplayWithCursor()

View File

@ -49,18 +49,23 @@ public extension SessionCtl {
} }
} }
if state.type == .ofAssociates { switch state.type {
case .ofDeactivated, .ofEmpty, .ofAbortion, .ofCommitting, .ofMarking: break
case .ofAssociates:
handleIMKCandidatesPrepared(state.candidates, prefix: "") handleIMKCandidatesPrepared(state.candidates, prefix: "")
} else if state.type == .ofSymbolTable { case .ofInputting where state.isCandidateContainer:
// / JIS 使 handleIMKCandidatesPrepared(state.candidates, prefix: "🗲")
arrResult = state.candidates.map(\.value) case .ofCandidates:
} else if state.type == .ofCandidates {
guard !state.candidates.isEmpty else { return .init() } guard !state.candidates.isEmpty else { return .init() }
if state.candidates[0].keyArray.joined(separator: "-").contains("_punctuation") { if state.candidates[0].keyArray.joined(separator: "-").contains("_punctuation") {
arrResult = state.candidates.map(\.value) // arrResult = state.candidates.map(\.value) //
} else { } else {
handleIMKCandidatesPrepared(state.candidates) handleIMKCandidatesPrepared(state.candidates)
} }
case .ofSymbolTable:
// / JIS 使
arrResult = state.candidates.map(\.value)
default: break
} }
return arrResult return arrResult
@ -113,17 +118,21 @@ public extension SessionCtl {
} }
} }
if state.type == .ofAssociates { switch state.type {
case .ofAssociates:
fixIndexForIMKCandidates(&indexDeducted, prefix: "", source: candidateString) fixIndexForIMKCandidates(&indexDeducted, prefix: "", source: candidateString)
} else if state.type == .ofSymbolTable { case .ofInputting where state.isCandidateContainer:
fixIndexForIMKCandidates(&indexDeducted, prefix: "🗲", source: candidateString)
case .ofSymbolTable:
fixSymbolIndexForIMKCandidates() fixSymbolIndexForIMKCandidates()
} else if state.type == .ofCandidates { case .ofCandidates:
guard !state.candidates.isEmpty else { return } guard !state.candidates.isEmpty else { return }
if state.candidates[0].keyArray.description.contains("_punctuation") { if state.candidates[0].keyArray.description.contains("_punctuation") {
fixSymbolIndexForIMKCandidates() // fixSymbolIndexForIMKCandidates() //
} else { } else {
fixIndexForIMKCandidates(&indexDeducted, source: candidateString) fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
} }
default: break
} }
candidatePairSelectionConfirmed(at: indexDeducted) candidatePairSelectionConfirmed(at: indexDeducted)
} }

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Quick Candidates" = "Quick Candidates";
"Alvin Liu (Imitative)" = "Alvin Liu (Imitative)"; "Alvin Liu (Imitative)" = "Alvin Liu (Imitative)";
"Previous intonation has been overridden." = "Previous intonation has been overridden."; "Previous intonation has been overridden." = "Previous intonation has been overridden.";
"It will attempt to combine with the incoming phonabet input." = "It will attempt to combine with the incoming phonabet input."; "It will attempt to combine with the incoming phonabet input." = "It will attempt to combine with the incoming phonabet input.";

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Quick Candidates" = "Quick Candidates";
"Alvin Liu (Imitative)" = "Alvin Liu (Imitative)"; "Alvin Liu (Imitative)" = "Alvin Liu (Imitative)";
"Previous intonation has been overridden." = "Previous intonation has been overridden."; "Previous intonation has been overridden." = "Previous intonation has been overridden.";
"It will attempt to combine with the incoming phonabet input." = "It will attempt to combine with the incoming phonabet input."; "It will attempt to combine with the incoming phonabet input." = "It will attempt to combine with the incoming phonabet input.";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音入力アプリ"; "vChewing" = "威注音入力アプリ";
"Quick Candidates" = "早速候補";
"Alvin Liu (Imitative)" = "劉又銘擬音注音配列"; "Alvin Liu (Imitative)" = "劉又銘擬音注音配列";
"Previous intonation has been overridden." = "後ろ側の漢字の音調を書き直しました。"; "Previous intonation has been overridden." = "後ろ側の漢字の音調を書き直しました。";
"It will attempt to combine with the incoming phonabet input." = "この音調は次の注音入力と組み合わす。"; "It will attempt to combine with the incoming phonabet input." = "この音調は次の注音入力と組み合わす。";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音输入法"; "vChewing" = "威注音输入法";
"Quick Candidates" = "快速候选";
"Alvin Liu (Imitative)" = "刘又铭拟音注音排列"; "Alvin Liu (Imitative)" = "刘又铭拟音注音排列";
"Previous intonation has been overridden." = "已覆写游标身后的汉字的音调。"; "Previous intonation has been overridden." = "已覆写游标身后的汉字的音调。";
"It will attempt to combine with the incoming phonabet input." = "该声调亦会尝试与接下来输入的注音相组合。"; "It will attempt to combine with the incoming phonabet input." = "该声调亦会尝试与接下来输入的注音相组合。";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音輸入法"; "vChewing" = "威注音輸入法";
"Quick Candidates" = "快速候選";
"Alvin Liu (Imitative)" = "劉又銘擬音注音排列"; "Alvin Liu (Imitative)" = "劉又銘擬音注音排列";
"Previous intonation has been overridden." = "已覆寫游標身後的漢字的音調。"; "Previous intonation has been overridden." = "已覆寫游標身後的漢字的音調。";
"It will attempt to combine with the incoming phonabet input." = "該聲調亦會嘗試與接下來輸入的注音相組合。"; "It will attempt to combine with the incoming phonabet input." = "該聲調亦會嘗試與接下來輸入的注音相組合。";