aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Adams <lukeclydeadams@gmail.com>2018-10-04 10:31:46 -0600
committerLuke Adams <lukeclydeadams@gmail.com>2018-10-04 10:51:19 -0600
commitc96015e634724a4ab02ab8dbf9c3994156e8bea7 (patch)
tree1862884f89b4e9f5362c408bca2c510c71f8f593
parente47c07681c6ddb458028a553ec3cb306b2e97e37 (diff)
downloadgit-bug-c96015e634724a4ab02ab8dbf9c3994156e8bea7.tar.gz
Enable editing comments in the term ui
-rw-r--r--termui/show_bug.go32
-rw-r--r--termui/termui.go36
2 files changed, 68 insertions, 0 deletions
diff --git a/termui/show_bug.go b/termui/show_bug.go
index aa52c8a3..6df744bd 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -184,6 +184,12 @@ func (sb *showBug) keybindings(g *gocui.Gui) error {
return err
}
+ // Edit
+ if err := g.SetKeybinding(showBugView, 'e', gocui.ModNone,
+ sb.edit); err != nil {
+ return err
+ }
+
// Labels
if err := g.SetKeybinding(showBugView, 'a', gocui.ModNone,
sb.addLabel); err != nil {
@@ -621,6 +627,32 @@ func (sb *showBug) toggleOpenClose(g *gocui.Gui, v *gocui.View) error {
}
}
+func (sb *showBug) edit(g *gocui.Gui, v *gocui.View) error {
+ if sb.isOnSide {
+ ui.msgPopup.Activate(msgPopupErrorTitle, "Selected field is not editable.")
+ return nil
+ }
+
+ snap := sb.bug.Snapshot()
+
+ op, err := snap.SearchTimelineItem(git.Hash(sb.selected))
+ if err != nil {
+ return err
+ }
+
+ switch op.(type) {
+ case *bug.AddCommentTimelineItem:
+ message := op.(*bug.AddCommentTimelineItem).Message
+ return editCommentWithEditor(sb.bug, op.Hash(), message)
+ case *bug.CreateTimelineItem:
+ preMessage := op.(*bug.CreateTimelineItem).Message
+ return editCommentWithEditor(sb.bug, op.Hash(), preMessage)
+ }
+
+ ui.msgPopup.Activate(msgPopupErrorTitle, "Selected field is not editable.")
+ return nil
+}
+
func (sb *showBug) addLabel(g *gocui.Gui, v *gocui.View) error {
c := ui.inputPopup.Activate("Add labels")
diff --git a/termui/termui.go b/termui/termui.go
index 45952705..5c39869b 100644
--- a/termui/termui.go
+++ b/termui/termui.go
@@ -4,6 +4,7 @@ package termui
import (
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/input"
+ "github.com/MichaelMure/git-bug/util/git"
"github.com/jroimartin/gocui"
"github.com/pkg/errors"
)
@@ -230,6 +231,41 @@ func addCommentWithEditor(bug *cache.BugCache) error {
return errTerminateMainloop
}
+func editCommentWithEditor(bug *cache.BugCache, target git.Hash, preMessage string) error {
+ // This is somewhat hacky.
+ // As there is no way to pause gocui, run the editor and restart gocui,
+ // we have to stop it entirely and start a new one later.
+ //
+ // - an error channel is used to route the returned error of this new
+ // instance into the original launch function
+ // - a custom error (errTerminateMainloop) is used to terminate the original
+ // instance's mainLoop. This error is then filtered.
+
+ ui.g.Close()
+ ui.g = nil
+
+ message, err := input.BugCommentEditorInput(ui.cache, preMessage)
+ if err != nil && err != input.ErrEmptyMessage {
+ return err
+ }
+
+ if err == input.ErrEmptyMessage {
+ // TODO: Allow comments to be deleted?
+ ui.msgPopup.Activate(msgPopupErrorTitle, "Empty message, aborting.")
+ } else if message == preMessage {
+ ui.msgPopup.Activate(msgPopupErrorTitle, "No changes found, aborting.")
+ } else {
+ err := bug.EditComment(target, message)
+ if err != nil {
+ return err
+ }
+ }
+
+ initGui(nil)
+
+ return errTerminateMainloop
+}
+
func setTitleWithEditor(bug *cache.BugCache) error {
// This is somewhat hacky.
// As there is no way to pause gocui, run the editor and restart gocui,