ctlCandUniv // Keep highlighted index if possible when flipping pages.
This commit is contained in:
parent
646554fe4b
commit
1a52ddfaa2
|
@ -13,7 +13,10 @@ import Cocoa
|
||||||
// 將之前 Zonble 重寫的 Voltaire 選字窗隔的橫向版本與縱向版本合併到同一個型別實體內。
|
// 將之前 Zonble 重寫的 Voltaire 選字窗隔的橫向版本與縱向版本合併到同一個型別實體內。
|
||||||
|
|
||||||
private class vwrCandidateUniversal: NSView {
|
private class vwrCandidateUniversal: NSView {
|
||||||
var highlightedIndex: Int = 0 { didSet { highlightedIndex = max(highlightedIndex, 0) } }
|
var highlightedIndex: Int = 0 {
|
||||||
|
didSet { highlightedIndex = min(max(highlightedIndex, 0), dispCandidatesWithLabels.count - 1) }
|
||||||
|
}
|
||||||
|
|
||||||
var action: Selector?
|
var action: Selector?
|
||||||
weak var target: AnyObject?
|
weak var target: AnyObject?
|
||||||
var isVerticalLayout: Bool = false
|
var isVerticalLayout: Bool = false
|
||||||
|
@ -462,7 +465,10 @@ public class ctlCandidateUniversal: ctlCandidate {
|
||||||
if pageCount == 1 { return highlightNextCandidate() }
|
if pageCount == 1 { return highlightNextCandidate() }
|
||||||
if currentPageIndex + 1 >= pageCount { clsSFX.beep() }
|
if currentPageIndex + 1 >= pageCount { clsSFX.beep() }
|
||||||
currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1
|
currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1
|
||||||
candidateView.highlightedIndex = 0
|
if currentPageIndex == pageCount - 1 {
|
||||||
|
candidateView.highlightedIndex = min(lastPageContentCount - 1, candidateView.highlightedIndex)
|
||||||
|
}
|
||||||
|
// candidateView.highlightedIndex = 0
|
||||||
layoutCandidateView()
|
layoutCandidateView()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -472,7 +478,10 @@ public class ctlCandidateUniversal: ctlCandidate {
|
||||||
if pageCount == 1 { return highlightPreviousCandidate() }
|
if pageCount == 1 { return highlightPreviousCandidate() }
|
||||||
if currentPageIndex == 0 { clsSFX.beep() }
|
if currentPageIndex == 0 { clsSFX.beep() }
|
||||||
currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1
|
currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1
|
||||||
candidateView.highlightedIndex = 0
|
if currentPageIndex == pageCount - 1 {
|
||||||
|
candidateView.highlightedIndex = min(lastPageContentCount - 1, candidateView.highlightedIndex)
|
||||||
|
}
|
||||||
|
// candidateView.highlightedIndex = 0
|
||||||
layoutCandidateView()
|
layoutCandidateView()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -530,6 +539,15 @@ extension ctlCandidateUniversal {
|
||||||
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastPageContentCount: Int {
|
||||||
|
guard let delegate = delegate else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
let totalCount = delegate.candidateCountForController(self)
|
||||||
|
let keyLabelCount = keyLabels.count
|
||||||
|
return totalCount % keyLabelCount
|
||||||
|
}
|
||||||
|
|
||||||
private func layoutCandidateView() {
|
private func layoutCandidateView() {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue