widget: test and document seekPosition

This commit adds a test for the seekPosition helper, a function which can
be used to move a combinedPos forward through a body of text until it approaches
a position.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-10-13 15:53:29 -04:00
committed by Elias Naur
parent dee3cc44f9
commit 2340664570
2 changed files with 88 additions and 0 deletions
+2
View File
@@ -1093,6 +1093,8 @@ func (e *Editor) closestPosition(pos combinedPos) combinedPos {
// seekPosition seeks to the position closest to needle, starting at start and returns true.
// If limit is non-zero, seekPosition stops seeks after limit runes and returns false.
// Start must have all fields valid, and needle must have at least one of runes, lineCol,
// or x+y valid. Start must be known to be before needle.
func seekPosition(lines []text.Line, alignment text.Alignment, width int, start, needle combinedPos, limit int) (combinedPos, bool) {
count := 0
// Advance until start is greater than or equal to needle.