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

Method FindNextDiffLine

internal/buffer/buffer.go:1426–1457  ·  view source on GitHub ↗

FindNextDiffLine returns the line number of the next block of diffs. If `startLine` is already in a block of diffs, lines in that block are skipped.

(startLine int, forward bool)

Source from the content-addressed store, hash-verified

1424// FindNextDiffLine returns the line number of the next block of diffs.
1425// If `startLine` is already in a block of diffs, lines in that block are skipped.
1426func (b *Buffer) FindNextDiffLine(startLine int, forward bool) (int, error) {
1427 if b.diff == nil {
1428 return 0, errors.New("no diff data")
1429 }
1430 startStatus, ok := b.diff[startLine]
1431 if !ok {
1432 startStatus = DSUnchanged
1433 }
1434 curLine := startLine
1435 for {
1436 curStatus, ok := b.diff[curLine]
1437 if !ok {
1438 curStatus = DSUnchanged
1439 }
1440 if curLine < 0 || curLine > b.LinesNum() {
1441 return 0, errors.New("no next diff hunk")
1442 }
1443 if curStatus != startStatus {
1444 if startStatus != DSUnchanged && curStatus == DSUnchanged {
1445 // Skip over the block of unchanged text
1446 startStatus = DSUnchanged
1447 } else {
1448 return curLine, nil
1449 }
1450 }
1451 if forward {
1452 curLine++
1453 } else {
1454 curLine--
1455 }
1456 }
1457}
1458
1459// SearchMatch returns true if the given location is within a match of the last search.
1460// It is used for search highlighting

Callers 2

DiffNextMethod · 0.80
DiffPreviousMethod · 0.80

Calls 1

LinesNumMethod · 0.65

Tested by

no test coverage detected