MCPcopy
hub / github.com/micro-editor/micro / DiffLA

Function DiffLA

internal/buffer/loc.go:63–83  ·  view source on GitHub ↗

The following functions require a buffer to know where newlines are Diff returns the distance between two locations

(a, b Loc, buf *LineArray)

Source from the content-addressed store, hash-verified

61
62// Diff returns the distance between two locations
63func DiffLA(a, b Loc, buf *LineArray) int {
64 if a.Y == b.Y {
65 if a.X > b.X {
66 return a.X - b.X
67 }
68 return b.X - a.X
69 }
70
71 // Make sure a is guaranteed to be less than b
72 if b.LessThan(a) {
73 a, b = b, a
74 }
75
76 loc := 0
77 for i := a.Y + 1; i < b.Y; i++ {
78 // + 1 for the newline
79 loc += util.CharacterCount(buf.LineBytes(i)) + 1
80 }
81 loc += util.CharacterCount(buf.LineBytes(a.Y)) - a.X + b.X + 1
82 return loc
83}
84
85// This moves the location one character to the right
86func (l Loc) right(buf *LineArray) Loc {

Callers 2

DoTextEventMethod · 0.85
DiffMethod · 0.85

Calls 3

CharacterCountFunction · 0.92
LineBytesMethod · 0.65
LessThanMethod · 0.45

Tested by

no test coverage detected