From d3cdc295053ba56664918843cc8d9e349f190326 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 3 Oct 2022 13:38:04 +0800 Subject: [PATCH] TDKCandidates // Reimplement certain features provided previously. --- .../CandidateWindow/CandidatePool.swift | 2 - .../INMUCandidateSuite/CtlCandidateTDK.swift | 72 +++++++++++++++---- .../CtlCandidateTDKBackports.swift | 72 +++++++++++++++---- 3 files changed, 114 insertions(+), 32 deletions(-) diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool.swift index a63d4a20..c912f6e7 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool.swift @@ -184,7 +184,6 @@ public class CandidatePool { var indexSpecified = indexSpecified highlightedIndex = indexSpecified if !(0.. Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == thePoolHorizontal.candidateRows.count - 1) + || (currentLayout == .vertical + && thePoolVertical.currentColumnNumber == thePoolVertical.candidateColumns.count - 1) + { + return highlightNextCandidate() + } switch currentLayout { case .horizontal: for _ in 0.. Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == thePoolHorizontal.candidateRows.count - 1) + || (currentLayout == .vertical + && thePoolVertical.currentColumnNumber == thePoolVertical.candidateColumns.count - 1) + { + return highlightNextCandidate() + } + switch currentLayout { + case .horizontal: + thePoolHorizontal.selectNewNeighborRow(direction: .down) + case .vertical: + thePoolVertical.selectNewNeighborColumn(direction: .right) + @unknown default: + return false + } + updateDisplay() + return true + } + @discardableResult override public func showPreviousPage() -> Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == 0) + || (currentLayout == .vertical && thePoolVertical.currentColumnNumber == 0) + { + return highlightPreviousCandidate() + } switch currentLayout { case .horizontal: for _ in 0.. Bool { - switch currentLayout { - case .horizontal: - thePoolHorizontal.selectNewNeighborRow(direction: .down) - case .vertical: - thePoolVertical.selectNewNeighborColumn(direction: .right) - @unknown default: - return false - } - updateDisplay() - return true - } - @discardableResult override public func showPreviousLine() -> Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == 0) + || (currentLayout == .vertical && thePoolVertical.currentColumnNumber == 0) + { + return highlightPreviousCandidate() + } switch currentLayout { case .horizontal: thePoolHorizontal.selectNewNeighborRow(direction: .up) @@ -151,8 +173,18 @@ public class CtlCandidateTDK: CtlCandidate { @discardableResult override public func highlightNextCandidate() -> Bool { switch currentLayout { case .horizontal: + if thePoolHorizontal.highlightedIndex == thePoolHorizontal.candidateDataAll.count - 1 { + thePoolHorizontal.highlightHorizontal(at: 0) + delegate?.buzz() + break + } thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.highlightedIndex + 1) case .vertical: + if thePoolVertical.highlightedIndex == thePoolVertical.candidateDataAll.count - 1 { + thePoolVertical.highlightVertical(at: 0) + delegate?.buzz() + break + } thePoolVertical.highlightVertical(at: thePoolVertical.highlightedIndex + 1) @unknown default: return false @@ -164,8 +196,18 @@ public class CtlCandidateTDK: CtlCandidate { @discardableResult override public func highlightPreviousCandidate() -> Bool { switch currentLayout { case .horizontal: + if thePoolHorizontal.highlightedIndex == 0 { + thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.candidateDataAll.count - 1) + delegate?.buzz() + break + } thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.highlightedIndex - 1) case .vertical: + if thePoolVertical.highlightedIndex == 0 { + thePoolVertical.highlightVertical(at: thePoolVertical.candidateDataAll.count - 1) + delegate?.buzz() + break + } thePoolVertical.highlightVertical(at: thePoolVertical.highlightedIndex - 1) @unknown default: return false @@ -179,11 +221,11 @@ public class CtlCandidateTDK: CtlCandidate { case .horizontal: let currentRow = thePoolHorizontal.candidateRows[thePoolHorizontal.currentRowNumber] let actualID = max(0, min(id, currentRow.count - 1)) - return thePoolHorizontal.candidateRows[thePoolHorizontal.currentRowNumber][actualID].index + return currentRow[actualID].index case .vertical: let currentColumn = thePoolVertical.candidateColumns[thePoolVertical.currentColumnNumber] let actualID = max(0, min(id, currentColumn.count - 1)) - return thePoolVertical.candidateColumns[thePoolVertical.currentColumnNumber][actualID].index + return currentColumn[actualID].index @unknown default: return 0 } diff --git a/Packages/vChewing_TDKCandidateBackports/Sources/TDKCandidateBackports/INMUCandidateSuiteBackports/CtlCandidateTDKBackports.swift b/Packages/vChewing_TDKCandidateBackports/Sources/TDKCandidateBackports/INMUCandidateSuiteBackports/CtlCandidateTDKBackports.swift index c37b0537..bef6d1ef 100644 --- a/Packages/vChewing_TDKCandidateBackports/Sources/TDKCandidateBackports/INMUCandidateSuiteBackports/CtlCandidateTDKBackports.swift +++ b/Packages/vChewing_TDKCandidateBackports/Sources/TDKCandidateBackports/INMUCandidateSuiteBackports/CtlCandidateTDKBackports.swift @@ -91,6 +91,12 @@ public class CtlCandidateTDKBackports: CtlCandidate { } @discardableResult override public func showNextPage() -> Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == thePoolHorizontal.candidateRows.count - 1) + || (currentLayout == .vertical + && thePoolVertical.currentColumnNumber == thePoolVertical.candidateColumns.count - 1) + { + return highlightNextCandidate() + } switch currentLayout { case .horizontal: for _ in 0.. Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == thePoolHorizontal.candidateRows.count - 1) + || (currentLayout == .vertical + && thePoolVertical.currentColumnNumber == thePoolVertical.candidateColumns.count - 1) + { + return highlightNextCandidate() + } + switch currentLayout { + case .horizontal: + thePoolHorizontal.selectNewNeighborRow(direction: .down) + case .vertical: + thePoolVertical.selectNewNeighborColumn(direction: .right) + @unknown default: + return false + } + updateDisplay() + return true + } + @discardableResult override public func showPreviousPage() -> Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == 0) + || (currentLayout == .vertical && thePoolVertical.currentColumnNumber == 0) + { + return highlightPreviousCandidate() + } switch currentLayout { case .horizontal: for _ in 0.. Bool { - switch currentLayout { - case .horizontal: - thePoolHorizontal.selectNewNeighborRow(direction: .down) - case .vertical: - thePoolVertical.selectNewNeighborColumn(direction: .right) - @unknown default: - return false - } - updateDisplay() - return true - } - @discardableResult override public func showPreviousLine() -> Bool { + if (currentLayout == .horizontal && thePoolHorizontal.currentRowNumber == 0) + || (currentLayout == .vertical && thePoolVertical.currentColumnNumber == 0) + { + return highlightPreviousCandidate() + } switch currentLayout { case .horizontal: thePoolHorizontal.selectNewNeighborRow(direction: .up) @@ -153,8 +175,18 @@ public class CtlCandidateTDKBackports: CtlCandidate { @discardableResult override public func highlightNextCandidate() -> Bool { switch currentLayout { case .horizontal: + if thePoolHorizontal.highlightedIndex == thePoolHorizontal.candidateDataAll.count - 1 { + thePoolHorizontal.highlightHorizontal(at: 0) + delegate?.buzz() + break + } thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.highlightedIndex + 1) case .vertical: + if thePoolVertical.highlightedIndex == thePoolVertical.candidateDataAll.count - 1 { + thePoolVertical.highlightVertical(at: 0) + delegate?.buzz() + break + } thePoolVertical.highlightVertical(at: thePoolVertical.highlightedIndex + 1) @unknown default: return false @@ -166,8 +198,18 @@ public class CtlCandidateTDKBackports: CtlCandidate { @discardableResult override public func highlightPreviousCandidate() -> Bool { switch currentLayout { case .horizontal: + if thePoolHorizontal.highlightedIndex == 0 { + thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.candidateDataAll.count - 1) + delegate?.buzz() + break + } thePoolHorizontal.highlightHorizontal(at: thePoolHorizontal.highlightedIndex - 1) case .vertical: + if thePoolVertical.highlightedIndex == 0 { + thePoolVertical.highlightVertical(at: thePoolVertical.candidateDataAll.count - 1) + delegate?.buzz() + break + } thePoolVertical.highlightVertical(at: thePoolVertical.highlightedIndex - 1) @unknown default: return false @@ -181,11 +223,11 @@ public class CtlCandidateTDKBackports: CtlCandidate { case .horizontal: let currentRow = thePoolHorizontal.candidateRows[thePoolHorizontal.currentRowNumber] let actualID = max(0, min(id, currentRow.count - 1)) - return thePoolHorizontal.candidateRows[thePoolHorizontal.currentRowNumber][actualID].index + return currentRow[actualID].index case .vertical: let currentColumn = thePoolVertical.candidateColumns[thePoolVertical.currentColumnNumber] let actualID = max(0, min(id, currentColumn.count - 1)) - return thePoolVertical.candidateColumns[thePoolVertical.currentColumnNumber][actualID].index + return currentColumn[actualID].index @unknown default: return 0 }