diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/app_config.go | 2 | ||||
-rw-r--r-- | pkg/gui/commit_message_panel.go | 47 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 17 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 1 | ||||
-rw-r--r-- | pkg/gui/gui.go | 1 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 1 |
6 files changed, 46 insertions, 23 deletions
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3c272e520..ae713a212 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -222,6 +222,8 @@ func GetDefaultConfig() []byte { - white optionsTextColor: - blue + commitLength: + show: true update: method: prompt # can be: prompt | background | never days: 14 # how often a update is checked for diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 36718680f..99d649102 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -1,6 +1,9 @@ package gui import ( + "strconv" + "strings" + "github.com/jesseduffield/gocui" ) @@ -33,11 +36,6 @@ func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error { return gui.switchFocus(g, v, gui.getFilesView(g)) } -func (gui *Gui) handleNewlineCommitMessage(g *gocui.Gui, v *gocui.View) error { - v.EditNewLine() - return nil -} - func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { message := gui.Tr.TemplateLocalize( "CloseConfirm", @@ -48,3 +46,42 @@ func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { ) return gui.renderString(g, "options", message) } + +func (gui *Gui) simpleEditor(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.KeyTab: + v.EditNewLine() + case key == gocui.KeySpace: + v.EditWrite(' ') + case key == gocui.KeyInsert: + v.Overwrite = !v.Overwrite + default: + v.EditWrite(ch) + } + + gui.RenderCommitLength() +} + +func (gui *Gui) getBufferLength(view *gocui.View) string { + return " " + strconv.Itoa(strings.Count(view.Buffer(), "")-1) + " " +} + +func (gui *Gui) RenderCommitLength() { + if !gui.Config.GetUserConfig().GetBool("gui.commitLength.show") { + return + } + v := gui.getCommitMessageView(gui.g) + v.Subtitle = gui.getBufferLength(v) +} diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 0bb633f32..58577e430 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -115,20 +115,6 @@ func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, t return nil } -func (gui *Gui) handleNewline(g *gocui.Gui, v *gocui.View) error { - // resising ahead of time so that the top line doesn't get hidden to make - // room for the cursor on the second line - x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, v.Buffer()) - if _, err := g.SetView("confirmation", x0, y0, x1, y1+1, 0); err != nil { - if err != gocui.ErrUnknownView { - return err - } - } - - v.EditNewLine() - return nil -} - func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error { actions := gui.Tr.TemplateLocalize( "CloseConfirm", @@ -143,9 +129,6 @@ func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*go if err := g.SetKeybinding("confirmation", gocui.KeyEnter, gocui.ModNone, gui.wrappedConfirmationFunction(handleConfirm)); err != nil { return err } - if err := g.SetKeybinding("confirmation", gocui.KeyTab, gocui.ModNone, gui.handleNewline); err != nil { - return err - } return g.SetKeybinding("confirmation", gocui.KeyEsc, gocui.ModNone, gui.wrappedConfirmationFunction(handleClose)) } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index a4c187c9c..1971b3453 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -226,6 +226,7 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { g.Update(func(g *gocui.Gui) error { g.SetViewOnTop("commitMessage") gui.switchFocus(g, filesView, commitMessageView) + gui.RenderCommitLength() return nil }) return nil diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index bb2ed752b..bb395f9d2 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -262,6 +262,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { commitMessageView.Title = gui.Tr.SLocalize("CommitMessage") commitMessageView.FgColor = gocui.ColorWhite commitMessageView.Editable = true + commitMessageView.Editor = gocui.EditorFunc(gui.simpleEditor) } } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c6decc24f..494381749 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -70,7 +70,6 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "stash", Key: 'd', Modifier: gocui.ModNone, Handler: gui.handleStashDrop}, {ViewName: "commitMessage", Key: gocui.KeyEnter, Modifier: gocui.ModNone, Handler: gui.handleCommitConfirm}, {ViewName: "commitMessage", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleCommitClose}, - {ViewName: "commitMessage", Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.handleNewlineCommitMessage}, } // Would make these keybindings global but that interferes with editing |