Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ability to edit entries #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add more details to comments
  • Loading branch information
magnickolas committed Aug 26, 2020
commit 82971ea478d6b5e810db0aef049af31f1388edf7
2 changes: 1 addition & 1 deletion controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func keybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("entries", gocui.KeyCtrlR, gocui.ModNone, deleteItem); err != nil {
return err
}
if err := g.SetKeybinding("entries", gocui.KeyArrowRight, gocui.ModNone, editEntry); err != nil {
if err := g.SetKeybinding("entries", gocui.KeyArrowRight, gocui.ModNone, startEditingEntry); err != nil {
return err
}
if err := g.SetKeybinding("output", gocui.KeyCtrlS, gocui.ModNone, save); err != nil {
Expand Down
12 changes: 7 additions & 5 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,16 @@ func newEntry(g *gocui.Gui, v *gocui.View) error {
return err
}

// Edit existing entry
func editEntry(g *gocui.Gui, v *gocui.View) error {
// Enable edit mode for an existing entry
// After editing the details of the entry its end time will be updated
func startEditingEntry(g *gocui.Gui, v *gocui.View) error {
var err error
v.Highlight = false
ov, err := g.SetCurrentView("output")
if err != nil {
return err
}
if err = drawEntryBody(g, ov); err != nil {
if err = outputEntryDetails(g, ov); err != nil {
return err
}
ov.Editable = true
Expand All @@ -404,8 +405,9 @@ func editEntry(g *gocui.Gui, v *gocui.View) error {
return err
}

// Output only body of an entry for editing its text
func drawEntryBody(g *gocui.Gui, v *gocui.View) error {
// v will always equal output view
// This outputs only the details of the entry for the purpose of further editing it
func outputEntryDetails(g *gocui.Gui, v *gocui.View) error {
var err error

v.Clear()
Expand Down