Skip to content

Commit

Permalink
Searching for text will now land VOCR cursor on the right chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
vick08 committed Sep 1, 2024
1 parent a271b37 commit 400a8a3
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions VOCR/OCRTextSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ class OCRTextSearch {
return
}

for (lineIndex, line) in Navigation.displayResults.enumerated() {
let lineText = line.map { $0.value }.joined(separator: " ")

if lineText.localizedCaseInsensitiveContains(query) {
// Found the query! Probably OK to move VOCR cursor there!
Navigation.l = lineIndex
Accessibility.speakWithSynthesizer("Found '\(query)' on line \(lineIndex + 1)")
return
}
}
for (lineIndex, line) in Navigation.displayResults.enumerated() {
let lineText = line.map { $0.value }.joined(separator: " ")

if lineText.localizedCaseInsensitiveContains(query) {
// Found the line containing the search text

// Now, find the specific item(s) within the line and move VOCR cursor there
for (wordIndex, word) in line.enumerated() {
if word.value.localizedCaseInsensitiveContains(query) {
Navigation.l = lineIndex
Navigation.w = wordIndex
print("Found '\(query)' at line \(lineIndex + 1), word \(wordIndex + 1)")
Accessibility.speakWithSynthesizer("Found")
}
}
return
}
}

Accessibility.speakWithSynthesizer("Not found '\(query)'.")
Accessibility.speakWithSynthesizer("Text not found '\(query)'.")
}

func showSearchDialog() {
Expand Down

0 comments on commit 400a8a3

Please sign in to comment.