mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
match beginning and end of line correctly in FindNext and ReplaceRegex (#3575)
This commit is contained in:
@@ -47,6 +47,16 @@ func (l Loc) LessEqual(b Loc) bool {
|
||||
return l == b
|
||||
}
|
||||
|
||||
// Clamp clamps a loc between start and end
|
||||
func (l Loc) Clamp(start, end Loc) Loc {
|
||||
if l.GreaterEqual(end) {
|
||||
return end
|
||||
} else if l.LessThan(start) {
|
||||
return start
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// The following functions require a buffer to know where newlines are
|
||||
|
||||
// Diff returns the distance between two locations
|
||||
@@ -139,10 +149,5 @@ func ByteOffset(pos Loc, buf *Buffer) int {
|
||||
|
||||
// clamps a loc within a buffer
|
||||
func clamp(pos Loc, la *LineArray) Loc {
|
||||
if pos.GreaterEqual(la.End()) {
|
||||
return la.End()
|
||||
} else if pos.LessThan(la.Start()) {
|
||||
return la.Start()
|
||||
}
|
||||
return pos
|
||||
return pos.Clamp(la.Start(), la.End())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user