runeOffsetToRowCol converts an absolute rune offset into (row, col).
(value string, offset int)
| 445 | |
| 446 | // runeOffsetToRowCol converts an absolute rune offset into (row, col). |
| 447 | func runeOffsetToRowCol(value string, offset int) (int, int) { |
| 448 | row, col := 0, 0 |
| 449 | i := 0 |
| 450 | for _, r := range value { |
| 451 | if i == offset { |
| 452 | return row, col |
| 453 | } |
| 454 | if r == '\n' { |
| 455 | row++ |
| 456 | col = 0 |
| 457 | } else { |
| 458 | col++ |
| 459 | } |
| 460 | i++ |
| 461 | } |
| 462 | return row, col |
| 463 | } |
| 464 | |
| 465 | // View delegates to the textarea. Chip labels are already plain text in the |
| 466 | // value, so no post-processing is needed. |