mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +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:
@@ -1027,6 +1027,28 @@ func (h *BufPane) FindPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// DiffNext searches forward until the beginning of the next block of diffs
|
||||
func (h *BufPane) DiffNext() bool {
|
||||
cur := h.Cursor.Loc.Y
|
||||
dl, err := h.Buf.FindNextDiffLine(cur, true)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
h.GotoLoc(buffer.Loc{0, dl})
|
||||
return true
|
||||
}
|
||||
|
||||
// DiffPrevious searches forward until the end of the previous block of diffs
|
||||
func (h *BufPane) DiffPrevious() bool {
|
||||
cur := h.Cursor.Loc.Y
|
||||
dl, err := h.Buf.FindNextDiffLine(cur, false)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
h.GotoLoc(buffer.Loc{0, dl})
|
||||
return true
|
||||
}
|
||||
|
||||
// Undo undoes the last action
|
||||
func (h *BufPane) Undo() bool {
|
||||
h.Buf.Undo()
|
||||
@@ -1311,7 +1333,7 @@ func (h *BufPane) OpenFile() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// OpenFile opens a new file in the buffer
|
||||
// JumpLine asks the user to enter a line number to jump to
|
||||
func (h *BufPane) JumpLine() bool {
|
||||
InfoBar.Prompt("> ", "goto ", "Command", nil, func(resp string, canceled bool) {
|
||||
if !canceled {
|
||||
|
||||
@@ -708,6 +708,8 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"FindLiteral": (*BufPane).FindLiteral,
|
||||
"FindNext": (*BufPane).FindNext,
|
||||
"FindPrevious": (*BufPane).FindPrevious,
|
||||
"DiffNext": (*BufPane).DiffNext,
|
||||
"DiffPrevious": (*BufPane).DiffPrevious,
|
||||
"Center": (*BufPane).Center,
|
||||
"Undo": (*BufPane).Undo,
|
||||
"Redo": (*BufPane).Redo,
|
||||
|
||||
@@ -41,6 +41,8 @@ var bufdefaults = map[string]string{
|
||||
"Alt-F": "FindLiteral",
|
||||
"Ctrl-n": "FindNext",
|
||||
"Ctrl-p": "FindPrevious",
|
||||
"Alt-[": "DiffPrevious|CursorStart",
|
||||
"Alt-]": "DiffNext|CursorEnd",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build !darwin
|
||||
// +build !darwin
|
||||
|
||||
package action
|
||||
@@ -43,6 +44,8 @@ var bufdefaults = map[string]string{
|
||||
"Alt-F": "FindLiteral",
|
||||
"Ctrl-n": "FindNext",
|
||||
"Ctrl-p": "FindPrevious",
|
||||
"Alt-[": "DiffPrevious|CursorStart",
|
||||
"Alt-]": "DiffNext|CursorEnd",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
|
||||
Reference in New Issue
Block a user