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

Method AdjustPos

texteditor/text/edit.go:105–146  ·  view source on GitHub ↗

AdjustPos adjusts the given text position as a function of the edit. if the position was within a deleted region of text, del determines what is returned

(pos lexer.Pos, del AdjustPosDel)

Source from the content-addressed store, hash-verified

103// if the position was within a deleted region of text, del determines
104// what is returned
105func (te *Edit) AdjustPos(pos lexer.Pos, del AdjustPosDel) lexer.Pos {
106 if te == nil {
107 return pos
108 }
109 if pos.IsLess(te.Reg.Start) || pos == te.Reg.Start {
110 return pos
111 }
112 dl := te.Reg.End.Ln - te.Reg.Start.Ln
113 if pos.Ln > te.Reg.End.Ln {
114 if te.Delete {
115 pos.Ln -= dl
116 } else {
117 pos.Ln += dl
118 }
119 return pos
120 }
121 if te.Delete {
122 if pos.Ln < te.Reg.End.Ln || pos.Ch < te.Reg.End.Ch {
123 switch del {
124 case AdjustPosDelStart:
125 return te.Reg.Start
126 case AdjustPosDelEnd:
127 return te.Reg.End
128 case AdjustPosDelErr:
129 return lexer.PosErr
130 }
131 }
132 // this means pos.Ln == te.Reg.End.Ln, Ch >= end
133 if dl == 0 {
134 pos.Ch -= (te.Reg.End.Ch - te.Reg.Start.Ch)
135 } else {
136 pos.Ch -= te.Reg.End.Ch
137 }
138 } else {
139 if dl == 0 {
140 pos.Ch += (te.Reg.End.Ch - te.Reg.Start.Ch)
141 } else {
142 pos.Ln += dl
143 }
144 }
145 return pos
146}
147
148// AdjustPosIfAfterTime checks the time stamp and IfAfterTime,
149// it adjusts the given text position as a function of the edit

Callers 3

AdjustPosIfAfterTimeMethod · 0.95
AdjustRegMethod · 0.95
InsertAtCursorMethod · 0.80

Calls 1

IsLessMethod · 0.80

Tested by

no test coverage detected