MCPcopy Create free account
hub / github.com/cogentcore/core / validPos

Method validPos

texteditor/text/lines.go:742–762  ·  view source on GitHub ↗

Edits validPos returns a position that is in a valid range

(pos lexer.Pos)

Source from the content-addressed store, hash-verified

740
741// validPos returns a position that is in a valid range
742func (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

Callers 4

ValidPosMethod · 0.95
regionMethod · 0.95
regionRectMethod · 0.95
insertTextImplMethod · 0.95

Calls 1

numLinesMethod · 0.95

Tested by

no test coverage detected