Zonble: Refactor the handling of candidate window types.
This commit is contained in:
parent
06c90fd4f2
commit
195d47a6f1
|
@ -20,7 +20,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
|||
import Cocoa
|
||||
import InputMethodKit
|
||||
|
||||
extension Bool {
|
||||
private extension Bool {
|
||||
var state: NSControl.StateValue {
|
||||
self ? .on : .off
|
||||
}
|
||||
|
@ -30,11 +30,14 @@ private let kMinKeyLabelSize: CGFloat = 10
|
|||
|
||||
private var gCurrentCandidateController: CandidateController?
|
||||
|
||||
private extension CandidateController {
|
||||
static let horizontal = HorizontalCandidateController()
|
||||
static let vertical = VerticalCandidateController()
|
||||
}
|
||||
|
||||
@objc(ctlInputMethod)
|
||||
class ctlInputMethod: IMKInputController {
|
||||
|
||||
private static let horizontalCandidateController = HorizontalCandidateController()
|
||||
private static let verticalCandidateController = VerticalCandidateController()
|
||||
private static let tooltipController = TooltipController()
|
||||
|
||||
// MARK: -
|
||||
|
@ -464,20 +467,37 @@ extension ctlInputMethod {
|
|||
|
||||
private func show(candidateWindowWith state: InputState, client: Any!) {
|
||||
let useVerticalMode: Bool = {
|
||||
var useVerticalMode = false
|
||||
var candidates: [String] = []
|
||||
if let state = state as? InputState.ChoosingCandidate {
|
||||
return state.useVerticalMode
|
||||
useVerticalMode = state.useVerticalMode
|
||||
candidates = state.candidates
|
||||
} else if let state = state as? InputState.AssociatedPhrases {
|
||||
return state.useVerticalMode
|
||||
useVerticalMode = state.useVerticalMode
|
||||
candidates = state.candidates
|
||||
}
|
||||
if useVerticalMode == true {
|
||||
return true
|
||||
}
|
||||
candidates.sort {
|
||||
return $0.count > $1.count
|
||||
}
|
||||
// If there is a candidate which is too long, we use the vertical
|
||||
// candidate list window automatically.
|
||||
if candidates.first?.count ?? 0 > 8 {
|
||||
// return true // 禁用這一項。威注音回頭會換候選窗格。
|
||||
}
|
||||
return false
|
||||
}()
|
||||
|
||||
gCurrentCandidateController?.delegate = nil
|
||||
|
||||
if useVerticalMode {
|
||||
gCurrentCandidateController = ctlInputMethod.verticalCandidateController
|
||||
gCurrentCandidateController = .vertical
|
||||
} else if Preferences.useHorizontalCandidateList {
|
||||
gCurrentCandidateController = ctlInputMethod.horizontalCandidateController
|
||||
gCurrentCandidateController = .horizontal
|
||||
} else {
|
||||
gCurrentCandidateController = ctlInputMethod.verticalCandidateController
|
||||
gCurrentCandidateController = .vertical
|
||||
}
|
||||
|
||||
// set the attributes for the candidate panel (which uses NSAttributedString)
|
||||
|
@ -551,7 +571,7 @@ extension ctlInputMethod {
|
|||
|
||||
extension ctlInputMethod: KeyHandlerDelegate {
|
||||
func candidateController(for keyHandler: KeyHandler) -> Any {
|
||||
gCurrentCandidateController ?? ctlInputMethod.verticalCandidateController
|
||||
gCurrentCandidateController ?? .vertical
|
||||
}
|
||||
|
||||
func keyHandler(_ keyHandler: KeyHandler, didSelectCandidateAt index: Int, candidateController controller: Any) {
|
||||
|
|
Loading…
Reference in New Issue