IMKCandidates // Better Shift+Tab/Space handling.

- This aligns their behaviors to how Voltaire MK3 does.
This commit is contained in:
ShikiSuen 2022-08-25 10:33:46 +08:00
parent 860289af46
commit f54c4d860b
1 changed files with 10 additions and 24 deletions

View File

@ -124,44 +124,24 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
// IMK
@discardableResult public func showNextPage() -> Bool {
guard delegate != nil else { return false }
if pageCount == 1 { return highlightNextCandidate() }
if currentPageIndex + 1 >= pageCount { clsSFX.beep() }
currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1
if selectedCandidateIndex == candidates(self).count - 1 { return false }
selectedCandidateIndex = min(selectedCandidateIndex + keyCount, candidates(self).count - 1)
do { currentLayout == .vertical ? moveRight(self) : moveDown(self) }
return true
}
// IMK
@discardableResult public func showPreviousPage() -> Bool {
guard delegate != nil else { return false }
if pageCount == 1 { return highlightPreviousCandidate() }
if currentPageIndex == 0 { clsSFX.beep() }
currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1
if selectedCandidateIndex == 0 { return true }
selectedCandidateIndex = max(selectedCandidateIndex - keyCount, 0)
do { currentLayout == .vertical ? moveLeft(self) : moveUp(self) }
return true
}
// IMK
@discardableResult public func highlightNextCandidate() -> Bool {
guard let delegate = delegate else { return false }
selectedCandidateIndex =
(selectedCandidateIndex + 1 >= delegate.candidateCountForController(self))
? 0 : selectedCandidateIndex + 1
do { currentLayout == .vertical ? moveDown(self) : moveRight(self) }
return true
}
// IMK
@discardableResult public func highlightPreviousCandidate() -> Bool {
guard let delegate = delegate else { return false }
selectedCandidateIndex =
(selectedCandidateIndex == 0)
? delegate.candidateCountForController(self) - 1 : selectedCandidateIndex - 1
do { currentLayout == .vertical ? moveUp(self) : moveLeft(self) }
return true
}
@ -230,15 +210,21 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
guard let delegate = delegate else { return }
if input.isEsc || input.isBackSpace || input.isDelete || (input.isShiftHold && !input.isSpace) {
_ = delegate.sharedEventHandler(event)
} else if input.isSymbolMenuPhysicalKey || input.isSpace {
} else if input.isSymbolMenuPhysicalKey {
//
switch currentLayout {
case .horizontal: input.isShiftHold ? moveUp(self) : moveDown(self)
case .vertical: input.isShiftHold ? moveLeft(self) : moveRight(self)
}
} else if input.isSpace {
switch mgrPrefs.specifyShiftSpaceKeyBehavior {
case true: _ = input.isShiftHold ? highlightNextCandidate() : showNextPage()
case false: _ = input.isShiftHold ? showNextPage() : highlightNextCandidate()
}
} else if input.isTab {
switch currentLayout {
case .horizontal: input.isShiftHold ? moveLeft(self) : moveRight(self)
case .vertical: input.isShiftHold ? moveUp(self) : moveDown(self)
switch mgrPrefs.specifyShiftTabKeyBehavior {
case true: _ = input.isShiftHold ? showPreviousPage() : showNextPage()
case false: _ = input.isShiftHold ? highlightPreviousCandidate() : highlightNextCandidate()
}
} else {
if let newChar = ctlCandidateIMK.defaultIMKSelectionKey[event.keyCode] {