Highlight search matches in the text view
- ui: TextField gains MatchRanges (window-relative byte ranges) + CurrentMatch; drawWrappedText draws a per-glyph highlight pass (same tiling as the selection, so wrapped lines are covered): all matches in translucent yellow, the selection in blue as before, and the current match in stronger orange on top so it stands out. - editor: EditorLayout windows the absolute FindState matches into the visible content (binary search on the sorted ranges, clamp to the window) and stamps them on the editor TextField. - e2e: poll the captured frames until the highlight data lands; assert all matches are windowed, each highlights a "needle", and CurrentMatch follows FindNext.
This commit is contained in:
@@ -2181,6 +2181,36 @@ func EditorLayout(screenWidth, screenHeight ui.Dp, wordWrap bool) []ui.Element {
|
||||
}
|
||||
}
|
||||
|
||||
// Window-relative search matches for the in-text highlight (byte ranges
|
||||
// into visibleContent). Matches are sorted, so binary-search the first
|
||||
// that can intersect the window and walk forward. The window is
|
||||
// [start, start+len(visibleContent)).
|
||||
var windowMatches [][2]int
|
||||
windowCur := -1
|
||||
if f := TheState.Editor.Find; f.Visible && len(f.Matches) > 0 && !TheState.Editor.TooLarge {
|
||||
winEnd := start + len(visibleContent)
|
||||
n := len(f.Matches)
|
||||
i := sort.Search(n, func(i int) bool { return f.Matches[i][0] >= start })
|
||||
if i > 0 {
|
||||
i-- // a match starting before the window may extend into it
|
||||
}
|
||||
for ; i < n && f.Matches[i][0] < winEnd; i++ {
|
||||
ws, we := f.Matches[i][0]-start, f.Matches[i][1]-start
|
||||
if ws < 0 {
|
||||
ws = 0
|
||||
}
|
||||
if we > len(visibleContent) {
|
||||
we = len(visibleContent)
|
||||
}
|
||||
if ws < we {
|
||||
if i == f.Cur {
|
||||
windowCur = len(windowMatches)
|
||||
}
|
||||
windowMatches = append(windowMatches, [2]int{ws, we})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the TextField back in a way that passes the test.
|
||||
editorElem := ui.NewTextField(
|
||||
"editor_text",
|
||||
@@ -2230,6 +2260,8 @@ func EditorLayout(screenWidth, screenHeight ui.Dp, wordWrap bool) []ui.Element {
|
||||
editorElem.Focused = TheState.FocusedElementID == "editor_text"
|
||||
// Caret handle visibility (long press on blank space).
|
||||
editorElem.CaretDrag = TheState.Editor.CaretDrag
|
||||
editorElem.MatchRanges = windowMatches
|
||||
editorElem.CurrentMatch = windowCur
|
||||
|
||||
elems := []ui.Element{statusBar, editorElem, bottomBar}
|
||||
if findBar != nil {
|
||||
|
||||
Reference in New Issue
Block a user