Edits validPos returns a position that is in a valid range
(pos lexer.Pos)
| 740 | |
| 741 | // validPos returns a position that is in a valid range |
| 742 | func (ls *Lines) validPos(pos lexer.Pos) lexer.Pos { |
| 743 | n := ls.numLines() |
| 744 | if n == 0 { |
| 745 | return lexer.PosZero |
| 746 | } |
| 747 | if pos.Ln < 0 { |
| 748 | pos.Ln = 0 |
| 749 | } |
| 750 | if pos.Ln >= n { |
| 751 | pos.Ln = n - 1 |
| 752 | pos.Ch = len(ls.lines[pos.Ln]) |
| 753 | return pos |
| 754 | } |
| 755 | pos.Ln = min(pos.Ln, n-1) |
| 756 | llen := len(ls.lines[pos.Ln]) |
| 757 | pos.Ch = min(pos.Ch, llen) |
| 758 | if pos.Ch < 0 { |
| 759 | pos.Ch = 0 |
| 760 | } |
| 761 | return pos |
| 762 | } |
| 763 | |
| 764 | // region returns a Edit representation of text between start and end positions |
| 765 | // returns nil if not a valid region. sets the timestamp on the Edit to now |
no test coverage detected