diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-11-28 13:14:48 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-11-28 20:48:17 +1100 |
commit | da3b0bf7c8aa6202d5eb9c8178f6648bc695336a (patch) | |
tree | cd0666ae4253469f8f2f1e349357be37bfb3d571 /pkg/gui/editors.go | |
parent | 90ade3225f55652d40c6f0266e50f5328390f02b (diff) |
Start on supporting auto-suggestions when checking out a branch
switch to other fuzzy package with no dependencies
Diffstat (limited to 'pkg/gui/editors.go')
-rw-r--r-- | pkg/gui/editors.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go new file mode 100644 index 000000000..baffd19a3 --- /dev/null +++ b/pkg/gui/editors.go @@ -0,0 +1,93 @@ +package gui + +import ( + "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +// we've just copy+pasted the editor from gocui to here so that we can also re- +// render the commit message length on each keypress +func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { + newlineKey, ok := gui.getKey(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline).(gocui.Key) + if !ok { + newlineKey = gocui.KeyTab + } + + switch { + case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: + v.EditDelete(true) + case key == gocui.KeyDelete: + v.EditDelete(false) + case key == gocui.KeyArrowDown: + v.MoveCursor(0, 1, false) + case key == gocui.KeyArrowUp: + v.MoveCursor(0, -1, false) + case key == gocui.KeyArrowLeft: + v.MoveCursor(-1, 0, false) + case key == gocui.KeyArrowRight: + v.MoveCursor(1, 0, false) + case key == newlineKey: + v.EditNewLine() + case key == gocui.KeySpace: + v.EditWrite(' ') + case key == gocui.KeyInsert: + v.Overwrite = !v.Overwrite + case key == gocui.KeyCtrlU: + v.EditDeleteToStartOfLine() + case key == gocui.KeyCtrlA: + v.EditGotoToStartOfLine() + case key == gocui.KeyCtrlE: + v.EditGotoToEndOfLine() + default: + v.EditWrite(ch) + } + + gui.RenderCommitLength() +} + +// we've just copy+pasted the editor from gocui to here so that we can also re- +// render the commit message length on each keypress +func (gui *Gui) editorWithCallback(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { + switch { + case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: + v.EditDelete(true) + case key == gocui.KeyDelete: + v.EditDelete(false) + case key == gocui.KeyArrowDown: + v.MoveCursor(0, 1, false) + case key == gocui.KeyArrowUp: + v.MoveCursor(0, -1, false) + case key == gocui.KeyArrowLeft: + v.MoveCursor(-1, 0, false) + case key == gocui.KeyArrowRight: + v.MoveCursor(1, 0, false) + case key == gocui.KeySpace: + v.EditWrite(' ') + case key == gocui.KeyInsert: + v.Overwrite = !v.Overwrite + case key == gocui.KeyCtrlU: + v.EditDeleteToStartOfLine() + case key == gocui.KeyCtrlA: + v.EditGotoToStartOfLine() + case key == gocui.KeyCtrlE: + v.EditGotoToEndOfLine() + default: + v.EditWrite(ch) + } + + input := v.Buffer() + branchNames := gui.getBranchNames() + + suggestions := utils.FuzzySearch(input, branchNames) + gui.setSuggestions(suggestions) +} + +func (gui *Gui) getBranchNames() []string { + result := make([]string, len(gui.State.Branches)) + + for i, branch := range gui.State.Branches { + result[i] = branch.Name + } + + return result +} |