summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-12-07 16:10:49 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-12-07 16:21:26 +1100
commit033c21754b6eb5ead47a56b9dbee54a976c7fcff (patch)
tree9784bd98de44ba36b24d886fc452f7769c856ae8
parent710abded6416c51f72285854c332881efab3e810 (diff)
fix commit message char count
-rw-r--r--pkg/gui/commit_message_panel.go35
-rw-r--r--pkg/gui/gui.go1
2 files changed, 36 insertions, 0 deletions
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go
index b087f5904..8d2d02524 100644
--- a/pkg/gui/commit_message_panel.go
+++ b/pkg/gui/commit_message_panel.go
@@ -83,3 +83,38 @@ func (gui *Gui) RenderCommitLength() {
v := gui.getCommitMessageView()
v.Subtitle = gui.getBufferLength(v)
}
+
+// 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) {
+ 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
+ case key == gocui.KeyCtrlU:
+ v.EditDeleteToStartOfLine()
+ case key == gocui.KeyCtrlA:
+ v.EditGotoToStartOfLine()
+ case key == gocui.KeyCtrlE:
+ v.EditGotoToEndOfLine()
+ default:
+ v.EditWrite(ch)
+ }
+
+ gui.RenderCommitLength()
+}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 3b6f2fb11..ba379fc56 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -553,6 +553,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
commitMessageView.FgColor = textColor
commitMessageView.Editable = true
+ commitMessageView.Editor = gocui.EditorFunc(gui.commitMessageEditor)
}
}