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

Function ParseCursorLocation

internal/buffer/buffer.go:1295–1316  ·  view source on GitHub ↗

ParseCursorLocation turns a cursor location like 10:5 (LINE:COL) into a loc

(cursorPositions []string)

Source from the content-addressed store, hash-verified

1293// ParseCursorLocation turns a cursor location like 10:5 (LINE:COL)
1294// into a loc
1295func ParseCursorLocation(cursorPositions []string) (Loc, error) {
1296 startpos := Loc{0, 0}
1297 var err error
1298
1299 // if no positions are available exit early
1300 if cursorPositions == nil {
1301 return startpos, errors.New("No cursor positions were provided.")
1302 }
1303
1304 startpos.Y, err = strconv.Atoi(cursorPositions[0])
1305 startpos.Y--
1306 if err == nil {
1307 if len(cursorPositions) > 1 {
1308 startpos.X, err = strconv.Atoi(cursorPositions[1])
1309 if startpos.X > 0 {
1310 startpos.X--
1311 }
1312 }
1313 }
1314
1315 return startpos, err
1316}
1317
1318// Line returns the string representation of the given line number
1319func (b *Buffer) Line(i int) string {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected