KeyHandler & ctlIME // Use ctlCandidateUniversal instead.
This commit is contained in:
parent
42e9ea4603
commit
5065727832
|
@ -35,10 +35,10 @@ public enum InputMode: String {
|
||||||
// MARK: - Delegate.
|
// MARK: - Delegate.
|
||||||
|
|
||||||
protocol KeyHandlerDelegate {
|
protocol KeyHandlerDelegate {
|
||||||
func ctlCandidate(for _: KeyHandler) -> Any
|
func ctlCandidate() -> ctlCandidate
|
||||||
func keyHandler(
|
func keyHandler(
|
||||||
_: KeyHandler, didSelectCandidateAt index: Int,
|
_: KeyHandler, didSelectCandidateAt index: Int,
|
||||||
ctlCandidate controller: Any
|
ctlCandidate controller: ctlCandidate
|
||||||
)
|
)
|
||||||
func keyHandler(_ keyHandler: KeyHandler, didRequestWriteUserPhraseWith state: InputState)
|
func keyHandler(_ keyHandler: KeyHandler, didRequestWriteUserPhraseWith state: InputState)
|
||||||
-> Bool
|
-> Bool
|
||||||
|
|
|
@ -37,7 +37,7 @@ extension KeyHandler {
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let inputText = input.inputText
|
let inputText = input.inputText
|
||||||
let charCode: UniChar = input.charCode
|
let charCode: UniChar = input.charCode
|
||||||
if let ctlCandidateCurrent = delegate!.ctlCandidate(for: self) as? ctlCandidate {
|
if let ctlCandidateCurrent = delegate?.ctlCandidate() {
|
||||||
// MARK: Cancel Candidate
|
// MARK: Cancel Candidate
|
||||||
|
|
||||||
let cancelCandidateKey =
|
let cancelCandidateKey =
|
||||||
|
@ -138,18 +138,21 @@ extension KeyHandler {
|
||||||
// MARK: Left Arrow
|
// MARK: Left Arrow
|
||||||
|
|
||||||
if input.isLeft {
|
if input.isLeft {
|
||||||
if ctlCandidateCurrent is ctlCandidateHorizontal {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
|
case .horizontal:
|
||||||
if !updated {
|
do {
|
||||||
IME.prtDebugIntel("1145148D")
|
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
||||||
errorCallback()
|
IME.prtDebugIntel("1145148D")
|
||||||
}
|
errorCallback()
|
||||||
} else {
|
}
|
||||||
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
|
}
|
||||||
if !updated {
|
case .vertical:
|
||||||
IME.prtDebugIntel("1919810D")
|
do {
|
||||||
errorCallback()
|
if !ctlCandidateCurrent.showPreviousPage() {
|
||||||
}
|
IME.prtDebugIntel("1919810D")
|
||||||
|
errorCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -168,18 +171,21 @@ extension KeyHandler {
|
||||||
// MARK: Right Arrow
|
// MARK: Right Arrow
|
||||||
|
|
||||||
if input.isRight {
|
if input.isRight {
|
||||||
if ctlCandidateCurrent is ctlCandidateHorizontal {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
|
case .horizontal:
|
||||||
if !updated {
|
do {
|
||||||
IME.prtDebugIntel("9B65138D")
|
if !ctlCandidateCurrent.highlightNextCandidate() {
|
||||||
errorCallback()
|
IME.prtDebugIntel("9B65138D")
|
||||||
}
|
errorCallback()
|
||||||
} else {
|
}
|
||||||
let updated: Bool = ctlCandidateCurrent.showNextPage()
|
}
|
||||||
if !updated {
|
case .vertical:
|
||||||
IME.prtDebugIntel("9244908D")
|
do {
|
||||||
errorCallback()
|
if !ctlCandidateCurrent.showNextPage() {
|
||||||
}
|
IME.prtDebugIntel("9244908D")
|
||||||
|
errorCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -198,18 +204,21 @@ extension KeyHandler {
|
||||||
// MARK: Up Arrow
|
// MARK: Up Arrow
|
||||||
|
|
||||||
if input.isUp {
|
if input.isUp {
|
||||||
if ctlCandidateCurrent is ctlCandidateHorizontal {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
|
case .horizontal:
|
||||||
if !updated {
|
do {
|
||||||
IME.prtDebugIntel("9B614524")
|
if !ctlCandidateCurrent.showPreviousPage() {
|
||||||
errorCallback()
|
IME.prtDebugIntel("9B614524")
|
||||||
}
|
errorCallback()
|
||||||
} else {
|
}
|
||||||
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
|
}
|
||||||
if !updated {
|
case .vertical:
|
||||||
IME.prtDebugIntel("ASD9908D")
|
do {
|
||||||
errorCallback()
|
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
||||||
}
|
IME.prtDebugIntel("ASD9908D")
|
||||||
|
errorCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -217,18 +226,21 @@ extension KeyHandler {
|
||||||
// MARK: Down Arrow
|
// MARK: Down Arrow
|
||||||
|
|
||||||
if input.isDown {
|
if input.isDown {
|
||||||
if ctlCandidateCurrent is ctlCandidateHorizontal {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
let updated: Bool = ctlCandidateCurrent.showNextPage()
|
case .horizontal:
|
||||||
if !updated {
|
do {
|
||||||
IME.prtDebugIntel("92B990DD")
|
if !ctlCandidateCurrent.showNextPage() {
|
||||||
errorCallback()
|
IME.prtDebugIntel("92B990DD")
|
||||||
}
|
errorCallback()
|
||||||
} else {
|
}
|
||||||
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
|
}
|
||||||
if !updated {
|
case .vertical:
|
||||||
IME.prtDebugIntel("6B99908D")
|
do {
|
||||||
errorCallback()
|
if !ctlCandidateCurrent.highlightNextCandidate() {
|
||||||
}
|
IME.prtDebugIntel("6B99908D")
|
||||||
|
errorCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,7 @@ import InputMethodKit
|
||||||
|
|
||||||
private let kMinKeyLabelSize: CGFloat = 10
|
private let kMinKeyLabelSize: CGFloat = 10
|
||||||
|
|
||||||
private var ctlCandidateCurrent: ctlCandidate?
|
private var ctlCandidateCurrent = ctlCandidateUniversal.init(.horizontal)
|
||||||
|
|
||||||
extension ctlCandidate {
|
|
||||||
static let horizontal = ctlCandidateUniversal(.horizontal)
|
|
||||||
static let vertical = ctlCandidateUniversal(.vertical)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc(ctlInputMethod)
|
@objc(ctlInputMethod)
|
||||||
class ctlInputMethod: IMKInputController {
|
class ctlInputMethod: IMKInputController {
|
||||||
|
@ -286,8 +281,8 @@ extension ctlInputMethod {
|
||||||
_ = state // Stop clang-format from ruining the parameters of this function.
|
_ = state // Stop clang-format from ruining the parameters of this function.
|
||||||
currentClient = nil
|
currentClient = nil
|
||||||
|
|
||||||
ctlCandidateCurrent?.delegate = nil
|
ctlCandidateCurrent.delegate = nil
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
|
|
||||||
if let previous = previous as? InputState.NotEmpty {
|
if let previous = previous as? InputState.NotEmpty {
|
||||||
|
@ -301,7 +296,7 @@ extension ctlInputMethod {
|
||||||
|
|
||||||
private func handle(state: InputState.Empty, previous: InputState, client: Any?) {
|
private func handle(state: InputState.Empty, previous: InputState, client: Any?) {
|
||||||
_ = state // Stop clang-format from ruining the parameters of this function.
|
_ = state // Stop clang-format from ruining the parameters of this function.
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
|
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
|
@ -324,7 +319,7 @@ extension ctlInputMethod {
|
||||||
) {
|
) {
|
||||||
_ = state // Stop clang-format from ruining the parameters of this function.
|
_ = state // Stop clang-format from ruining the parameters of this function.
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
|
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
|
@ -339,7 +334,7 @@ extension ctlInputMethod {
|
||||||
|
|
||||||
private func handle(state: InputState.Committing, previous: InputState, client: Any?) {
|
private func handle(state: InputState.Committing, previous: InputState, client: Any?) {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
|
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
|
@ -358,7 +353,7 @@ extension ctlInputMethod {
|
||||||
|
|
||||||
private func handle(state: InputState.Inputting, previous: InputState, client: Any?) {
|
private func handle(state: InputState.Inputting, previous: InputState, client: Any?) {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
|
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
|
@ -386,7 +381,7 @@ extension ctlInputMethod {
|
||||||
|
|
||||||
private func handle(state: InputState.Marking, previous: InputState, client: Any?) {
|
private func handle(state: InputState.Marking, previous: InputState, client: Any?) {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
return
|
return
|
||||||
|
@ -413,7 +408,7 @@ extension ctlInputMethod {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +425,7 @@ extension ctlInputMethod {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +442,7 @@ extension ctlInputMethod {
|
||||||
_ = previous // Stop clang-format from ruining the parameters of this function.
|
_ = previous // Stop clang-format from ruining the parameters of this function.
|
||||||
hideTooltip()
|
hideTooltip()
|
||||||
guard let client = client as? IMKTextInput else {
|
guard let client = client as? IMKTextInput else {
|
||||||
ctlCandidateCurrent?.visible = false
|
ctlCandidateCurrent.visible = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.setMarkedText(
|
client.setMarkedText(
|
||||||
|
@ -484,14 +479,14 @@ extension ctlInputMethod {
|
||||||
// 上面這句如果是 true 的話,就會是縱排;反之則為橫排。
|
// 上面這句如果是 true 的話,就會是縱排;反之則為橫排。
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlCandidateCurrent?.delegate = nil
|
ctlCandidateCurrent.delegate = nil
|
||||||
|
|
||||||
if useVerticalMode {
|
if useVerticalMode {
|
||||||
ctlCandidateCurrent = .vertical
|
ctlCandidateCurrent.currentLayout = .vertical
|
||||||
} else if mgrPrefs.useHorizontalCandidateList {
|
} else if mgrPrefs.useHorizontalCandidateList {
|
||||||
ctlCandidateCurrent = .horizontal
|
ctlCandidateCurrent.currentLayout = .horizontal
|
||||||
} else {
|
} else {
|
||||||
ctlCandidateCurrent = .vertical
|
ctlCandidateCurrent.currentLayout = .vertical
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the attributes for the candidate panel (which uses NSAttributedString)
|
// set the attributes for the candidate panel (which uses NSAttributedString)
|
||||||
|
@ -519,10 +514,10 @@ extension ctlInputMethod {
|
||||||
return finalReturnFont
|
return finalReturnFont
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlCandidateCurrent?.keyLabelFont = labelFont(
|
ctlCandidateCurrent.keyLabelFont = labelFont(
|
||||||
name: mgrPrefs.candidateKeyLabelFontName, size: keyLabelSize
|
name: mgrPrefs.candidateKeyLabelFontName, size: keyLabelSize
|
||||||
)
|
)
|
||||||
ctlCandidateCurrent?.candidateFont = candidateFont(
|
ctlCandidateCurrent.candidateFont = candidateFont(
|
||||||
name: mgrPrefs.candidateTextFontName, size: textSize
|
name: mgrPrefs.candidateTextFontName, size: textSize
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -530,15 +525,15 @@ extension ctlInputMethod {
|
||||||
let keyLabels =
|
let keyLabels =
|
||||||
candidateKeys.count > 4 ? Array(candidateKeys) : Array(mgrPrefs.defaultCandidateKeys)
|
candidateKeys.count > 4 ? Array(candidateKeys) : Array(mgrPrefs.defaultCandidateKeys)
|
||||||
let keyLabelSuffix = state is InputState.AssociatedPhrases ? "^" : ""
|
let keyLabelSuffix = state is InputState.AssociatedPhrases ? "^" : ""
|
||||||
ctlCandidateCurrent?.keyLabels = keyLabels.map {
|
ctlCandidateCurrent.keyLabels = keyLabels.map {
|
||||||
CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix)
|
CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlCandidateCurrent?.delegate = self
|
ctlCandidateCurrent.delegate = self
|
||||||
ctlCandidateCurrent?.reloadData()
|
ctlCandidateCurrent.reloadData()
|
||||||
currentClient = client
|
currentClient = client
|
||||||
|
|
||||||
ctlCandidateCurrent?.visible = true
|
ctlCandidateCurrent.visible = true
|
||||||
|
|
||||||
var lineHeightRect = NSRect(x: 0.0, y: 0.0, width: 16.0, height: 16.0)
|
var lineHeightRect = NSRect(x: 0.0, y: 0.0, width: 16.0, height: 16.0)
|
||||||
var cursor = 0
|
var cursor = 0
|
||||||
|
@ -558,14 +553,14 @@ extension ctlInputMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
if useVerticalMode {
|
if useVerticalMode {
|
||||||
ctlCandidateCurrent?.set(
|
ctlCandidateCurrent.set(
|
||||||
windowTopLeftPoint: NSPoint(
|
windowTopLeftPoint: NSPoint(
|
||||||
x: lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, y: lineHeightRect.origin.y - 4.0
|
x: lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, y: lineHeightRect.origin.y - 4.0
|
||||||
),
|
),
|
||||||
bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0
|
bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ctlCandidateCurrent?.set(
|
ctlCandidateCurrent.set(
|
||||||
windowTopLeftPoint: NSPoint(x: lineHeightRect.origin.x, y: lineHeightRect.origin.y - 4.0),
|
windowTopLeftPoint: NSPoint(x: lineHeightRect.origin.x, y: lineHeightRect.origin.y - 4.0),
|
||||||
bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0
|
bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0
|
||||||
)
|
)
|
||||||
|
@ -595,19 +590,13 @@ extension ctlInputMethod {
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
extension ctlInputMethod: KeyHandlerDelegate {
|
extension ctlInputMethod: KeyHandlerDelegate {
|
||||||
func ctlCandidate(for keyHandler: KeyHandler) -> Any {
|
func ctlCandidate() -> ctlCandidate { ctlCandidateCurrent }
|
||||||
_ = keyHandler // Stop clang-format from ruining the parameters of this function.
|
|
||||||
return ctlCandidateCurrent ?? .vertical
|
|
||||||
}
|
|
||||||
|
|
||||||
func keyHandler(
|
func keyHandler(
|
||||||
_ keyHandler: KeyHandler, didSelectCandidateAt index: Int,
|
_: KeyHandler, didSelectCandidateAt index: Int,
|
||||||
ctlCandidate controller: Any
|
ctlCandidate controller: ctlCandidate
|
||||||
) {
|
) {
|
||||||
_ = keyHandler // Stop clang-format from ruining the parameters of this function.
|
ctlCandidate(controller, didSelectCandidateAtIndex: index)
|
||||||
if let controller = controller as? ctlCandidate {
|
|
||||||
ctlCandidate(controller, didSelectCandidateAtIndex: index)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyHandler(_ keyHandler: KeyHandler, didRequestWriteUserPhraseWith state: InputState)
|
func keyHandler(_ keyHandler: KeyHandler, didRequestWriteUserPhraseWith state: InputState)
|
||||||
|
|
Loading…
Reference in New Issue