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] = []
//
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 value.isEmpty { return blankResult } // 西
if value.contains("_") { return blankResult }
@ -92,7 +98,17 @@ extension SessionCtl: CtlCandidateDelegate {
}
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)] {
@ -114,6 +130,7 @@ extension SessionCtl: CtlCandidateDelegate {
public func candidatePairSelectionConfirmed(at index: Int) {
guard let inputHandler = inputHandler else { return }
guard state.isCandidateContainer else { return }
switch state.type {
case .ofSymbolTable where (0 ..< state.node.members.count).contains(index):
let node = state.node.members[index]
@ -124,12 +141,10 @@ extension SessionCtl: CtlCandidateDelegate {
}
case .ofCandidates where (0 ..< state.candidates.count).contains(index):
let selectedValue = state.candidates[index]
if state.type == .ofCandidates {
inputHandler.consolidateNode(
candidate: selectedValue, respectCursorPushing: true,
preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection
)
}
inputHandler.consolidateNode(
candidate: selectedValue, respectCursorPushing: true,
preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection
)
var result: IMEStateProtocol = inputHandler.generateStateOfInputting()
defer { switchState(result) } //
if PrefMgr.shared.useSCPCTypingMode {
@ -157,6 +172,14 @@ extension SessionCtl: CtlCandidateDelegate {
withPair: .init(keyArray: selectedValue.keyArray, value: valueKept)
)
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
}
}

View File

@ -84,35 +84,33 @@ public extension SessionCtl {
? .vertical
: .horizontal)
let isInputtingWithCandidates = state.type == .ofInputting && state.isCandidateContainer
/// NSWindow()
candidateUI?.visible = false
///
if #available(macOS 10.13, *) {
candidateUI =
PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
if let candidateTDK = candidateUI as? CtlCandidateTDK {
let singleLine = isVerticalTyping || PrefMgr.shared.candidateWindowShowOnlyOneLine
candidateTDK.maxLinesPerPage = singleLine ? 1 : 4
}
///
let useIMK = PrefMgr.shared.useIMKCandidateWindow
candidateUI = useIMK ? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
} else {
candidateUI = CtlCandidateTDK(candidateLayout)
}
var singleLine = isVerticalTyping || PrefMgr.shared.candidateWindowShowOnlyOneLine
singleLine = singleLine || isInputtingWithCandidates
(candidateUI as? CtlCandidateTDK)?.maxLinesPerPage = singleLine ? 1 : 4
candidateUI?.candidateFont = Self.candidateFont(
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 {
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 = {

View File

@ -75,6 +75,7 @@ public extension SessionCtl {
setInlineDisplayWithCursor()
//
showTooltip(newState.tooltip, duration: newState.tooltipDuration)
if newState.isCandidateContainer { showCandidates() }
case .ofMarking:
candidateUI?.visible = false
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: "")
} else if state.type == .ofSymbolTable {
// / JIS 使
arrResult = state.candidates.map(\.value)
} else if state.type == .ofCandidates {
case .ofInputting where state.isCandidateContainer:
handleIMKCandidatesPrepared(state.candidates, prefix: "🗲")
case .ofCandidates:
guard !state.candidates.isEmpty else { return .init() }
if state.candidates[0].keyArray.joined(separator: "-").contains("_punctuation") {
arrResult = state.candidates.map(\.value) //
} else {
handleIMKCandidatesPrepared(state.candidates)
}
case .ofSymbolTable:
// / JIS 使
arrResult = state.candidates.map(\.value)
default: break
}
return arrResult
@ -113,17 +118,21 @@ public extension SessionCtl {
}
}
if state.type == .ofAssociates {
switch state.type {
case .ofAssociates:
fixIndexForIMKCandidates(&indexDeducted, prefix: "", source: candidateString)
} else if state.type == .ofSymbolTable {
case .ofInputting where state.isCandidateContainer:
fixIndexForIMKCandidates(&indexDeducted, prefix: "🗲", source: candidateString)
case .ofSymbolTable:
fixSymbolIndexForIMKCandidates()
} else if state.type == .ofCandidates {
case .ofCandidates:
guard !state.candidates.isEmpty else { return }
if state.candidates[0].keyArray.description.contains("_punctuation") {
fixSymbolIndexForIMKCandidates() //
} else {
fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
}
default: break
}
candidatePairSelectionConfirmed(at: indexDeducted)
}

View File

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

View File

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

View File

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