runeIndex is a rune-level strings.Index: first occurrence of needle in haystack, or -1. promptInput works in runes throughout because textarea's cursor is rune-addressed (column = rune count, not byte count).
(haystack, needle []rune)
| 366 | // haystack, or -1. promptInput works in runes throughout because textarea's |
| 367 | // cursor is rune-addressed (column = rune count, not byte count). |
| 368 | func runeIndex(haystack, needle []rune) int { |
| 369 | if len(needle) == 0 { |
| 370 | return 0 |
| 371 | } |
| 372 | if len(needle) > len(haystack) { |
| 373 | return -1 |
| 374 | } |
| 375 | for i := 0; i <= len(haystack)-len(needle); i++ { |
| 376 | match := true |
| 377 | for j := range needle { |
| 378 | if haystack[i+j] != needle[j] { |
| 379 | match = false |
| 380 | break |
| 381 | } |
| 382 | } |
| 383 | if match { |
| 384 | return i |
| 385 | } |
| 386 | } |
| 387 | return -1 |
| 388 | } |
| 389 | |
| 390 | // cursorRuneOffset returns the cursor as an absolute rune index into Value(). |
| 391 | // textarea only exposes (row, col) plus LineInfo, so we reconstruct it by |