MCPcopy Index your code
hub / github.com/micro-editor/micro / insert

Method insert

internal/buffer/line_array.go:204–224  ·  view source on GitHub ↗

Inserts a byte array at a given location

(pos Loc, value []byte)

Source from the content-addressed store, hash-verified

202
203// Inserts a byte array at a given location
204func (la *LineArray) insert(pos Loc, value []byte) {
205 la.lock.Lock()
206 defer la.lock.Unlock()
207
208 x, y := runeToByteIndex(pos.X, la.lines[pos.Y].data), pos.Y
209 for i := 0; i < len(value); i++ {
210 if value[i] == '\n' || (value[i] == '\r' && i < len(value)-1 && value[i+1] == '\n') {
211 la.split(Loc{x, y})
212 x = 0
213 y++
214
215 if value[i] == '\r' {
216 i++
217 }
218
219 continue
220 }
221 la.insertByte(Loc{x, y}, value[i])
222 x++
223 }
224}
225
226// InsertByte inserts a byte at a given location
227func (la *LineArray) insertByte(pos Loc, value byte) {

Callers

nothing calls this directly

Calls 5

splitMethod · 0.95
insertByteMethod · 0.95
runeToByteIndexFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected