Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement escape scan row #195

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ScanTree(private val context: Context) : ScanStateInterface {
*/
private var isInRow = false

/**
* This property indicates whether the current row should be escaped
*/
private var shouldEscapeRow = false

/**
* This property indicates the scanning direction
* Rows can scan up or down
Expand Down Expand Up @@ -95,6 +100,9 @@ class ScanTree(private val context: Context) : ScanStateInterface {
*/
private fun moveSelectionToNextNode() {
unhighlightCurrentNode()
if (shouldEscapeCurrentRow()) {
return
}
if (currentColumn < tree[currentRow].size - 1) {
currentColumn++
} else {
Expand All @@ -108,6 +116,9 @@ class ScanTree(private val context: Context) : ScanStateInterface {
*/
private fun moveSelectionToPreviousNode() {
unhighlightCurrentNode()
if (shouldEscapeCurrentRow()) {
return
}
if (currentColumn > 0) {
currentColumn--
} else {
Expand All @@ -116,6 +127,22 @@ class ScanTree(private val context: Context) : ScanStateInterface {
highlightCurrentNode()
}

/**
* This function checks if escaping the current row is necessary
* @return True if escaping the current row is necessary, false otherwise
*/
private fun shouldEscapeCurrentRow(): Boolean {
// If at the last node, activate the escape row
if (currentColumn == tree[currentRow].size - 1 && !shouldEscapeRow) {
shouldEscapeRow = true
highlightCurrentRow()
} else if (shouldEscapeRow) {
shouldEscapeRow = false
unhighlightCurrentRow()
}
return shouldEscapeRow
}

/**
* This function moves the selection to the next row
*/
Expand Down Expand Up @@ -239,6 +266,8 @@ class ScanTree(private val context: Context) : ScanStateInterface {

/**
* This function performs the selection
* It starts scanning if it is not already scanning
* It escapes the row if the row should be escaped
* If the scanning tree is in a row, it selects the current node
* If the scanning tree is not in a row, it selects the current row
*/
Expand All @@ -249,6 +278,12 @@ class ScanTree(private val context: Context) : ScanStateInterface {
println("Scanning started")
return
}
if (shouldEscapeRow) {
shouldEscapeRow = false
unhighlightCurrentRow()
reset()
return
}
if (isInRow) {
selectCurrentColumn()
stopScanning()
Expand Down
Loading