mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-22 00:37:12 +09:00
Goto next/previous diff commands + minor cleanups (#2759)
* Comment fix & gofmt fix * Goto next/previous diff commands These commands will work in `git` repositories or whenever `set diff on` is working. They are bound to `Alt-[` and `Alt-]` by default. I would prefer `Alt-Up` and `Alt-Down`, but that's already taken. There are no tests at the moment; I'm looking into writing some since that will be needed for the rest of the plan to make https://github.com/zyedidia/micro/discussions/2753 a reality. I'm not sure how difficult that will be. * Realign JSON in keybindings.md
This commit is contained in:
@@ -474,7 +474,7 @@ func (b *Buffer) GetName() string {
|
||||
return name
|
||||
}
|
||||
|
||||
//SetName changes the name for this buffer
|
||||
// SetName changes the name for this buffer
|
||||
func (b *Buffer) SetName(s string) {
|
||||
b.name = s
|
||||
}
|
||||
@@ -1211,6 +1211,41 @@ func (b *Buffer) DiffStatus(lineN int) DiffStatus {
|
||||
return b.diff[lineN]
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (b *Buffer) FindNextDiffLine(startLine int, forward bool) (int, error) {
|
||||
if b.diff == nil {
|
||||
return 0, errors.New("no diff data")
|
||||
}
|
||||
startStatus, ok := b.diff[startLine]
|
||||
if !ok {
|
||||
startStatus = DSUnchanged
|
||||
}
|
||||
curLine := startLine
|
||||
for {
|
||||
curStatus, ok := b.diff[curLine]
|
||||
if !ok {
|
||||
curStatus = DSUnchanged
|
||||
}
|
||||
if curLine < 0 || curLine > b.LinesNum() {
|
||||
return 0, errors.New("no next diff hunk")
|
||||
}
|
||||
if curStatus != startStatus {
|
||||
if startStatus != DSUnchanged && curStatus == DSUnchanged {
|
||||
// Skip over the block of unchanged text
|
||||
startStatus = DSUnchanged
|
||||
} else {
|
||||
return curLine, nil
|
||||
}
|
||||
}
|
||||
if forward {
|
||||
curLine++
|
||||
} else {
|
||||
curLine--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SearchMatch returns true if the given location is within a match of the last search.
|
||||
// It is used for search highlighting
|
||||
func (b *Buffer) SearchMatch(pos Loc) bool {
|
||||
|
||||
Reference in New Issue
Block a user