|
|
@@ -193,9 +193,11 @@ type edit struct {
|
|
|
inputFields []inputField
|
|
|
Path string
|
|
|
selected int
|
|
|
+ existing bool // flag to edit existing description
|
|
|
err error // not implemented
|
|
|
}
|
|
|
|
|
|
+// constructor for the edit widget
|
|
|
func newEditWidget(path string) widget {
|
|
|
// data prep
|
|
|
var e edit
|
|
|
@@ -207,6 +209,8 @@ func newEditWidget(path string) widget {
|
|
|
if err != nil {
|
|
|
return e
|
|
|
}
|
|
|
+
|
|
|
+ e.existing = true
|
|
|
} else { // if path is not existing issue, create new Issue with sensible defaults
|
|
|
issue = Issue{
|
|
|
Path: path, Title: parsePathToHuman(path),
|
|
|
@@ -336,7 +340,11 @@ func (e edit) update(msg tea.Msg) (widget, tea.Cmd) {
|
|
|
}
|
|
|
}
|
|
|
case createResult:
|
|
|
- cmds = append(cmds, e.editBlankDescription(Issue(msg)))
|
|
|
+ if !e.existing {
|
|
|
+ cmds = append(cmds, e.editBlankDescription(Issue(msg)))
|
|
|
+ } else {
|
|
|
+ cmds = append(cmds, e.editExistingDescription(Issue(msg)))
|
|
|
+ }
|
|
|
case editorResult:
|
|
|
if msg.err != nil {
|
|
|
e.err = msg.err
|
|
|
@@ -422,7 +430,7 @@ func (e edit) createIssueObject() tea.Msg {
|
|
|
// Wraps a tea.Cmd function, passes an initialized Issue to WriteIssue()
|
|
|
func (e edit) write(issue Issue) tea.Cmd {
|
|
|
return func() tea.Msg {
|
|
|
- result, err := WriteIssue(issue, false)
|
|
|
+ result, err := WriteIssue(issue, true)
|
|
|
if err != nil {
|
|
|
return writeResult(err)
|
|
|
}
|
|
|
@@ -449,7 +457,22 @@ func (e edit) editBlankDescription(issue Issue) tea.Cmd {
|
|
|
}
|
|
|
|
|
|
// does this just call InvokeEditor?
|
|
|
-func (e edit) editExistingDescription(issue Issue) tea.Cmd { return func() tea.Msg { return "" } }
|
|
|
+func (e edit) editExistingDescription(issue Issue) tea.Cmd {
|
|
|
+ err := InvokeEditor(filepath.Join(e.Path, "description"))
|
|
|
+ if err != nil {
|
|
|
+ return func() tea.Msg { return editorResult{issue: issue, err: err} }
|
|
|
+ }
|
|
|
+ data, err := ReadTemplate(filepath.Join(e.Path, "description"))
|
|
|
+
|
|
|
+ var output string
|
|
|
+ for _, line := range data {
|
|
|
+ output = output + line
|
|
|
+ }
|
|
|
+
|
|
|
+ issue.Description = Field{Path: "/description", Data: output}
|
|
|
+
|
|
|
+ return func() tea.Msg { return editorResult{issue: issue, err: err} }
|
|
|
+}
|
|
|
|
|
|
// render cmd for create widget
|
|
|
func (e edit) render() tea.Msg {
|
|
|
@@ -502,7 +525,19 @@ func (e edit) keyhelp() string {
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// enforce widget interface compliance
|
|
|
-func (i Issue) update(tea.Msg) (widget, tea.Cmd) { return i, nil }
|
|
|
+func (i Issue) update(msg tea.Msg) (widget, tea.Cmd) {
|
|
|
+ var cmds []tea.Cmd
|
|
|
+ switch msg := msg.(type) {
|
|
|
+ case tea.KeyMsg:
|
|
|
+ switch msg.String() {
|
|
|
+ case "e":
|
|
|
+ cmds = append(cmds, i.edit)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return i, tea.Batch(cmds...)
|
|
|
+}
|
|
|
+
|
|
|
+func (i Issue) edit() tea.Msg { return newEditWidget(i.Path) }
|
|
|
|
|
|
// render cmd for Issue widget
|
|
|
func (i Issue) render() tea.Msg {
|
|
|
@@ -546,7 +581,7 @@ func (i Issue) render() tea.Msg {
|
|
|
// keyhelp cmd for Issue widget
|
|
|
func (i Issue) keyhelp() string {
|
|
|
var output string
|
|
|
- output = output + "\nj/k: down/up\t\tctrl+c: quit"
|
|
|
+ output = output + "\ne: edit issue\t\tctrl+c: quit"
|
|
|
return output
|
|
|
}
|
|
|
|