diff --git a/main.go b/main.go index 6a447cb..b1a80b9 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "os/exec" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" @@ -145,6 +146,10 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { _, cmd := m.noteView.Update(loadNote{path: msg.path}) return m, cmd + case loadNote: + _, cmd := m.noteView.Update(msg) + return m, cmd + case loadedNote: // Forward loaded note to noteView _, cmd := m.noteView.Update(msg) @@ -215,6 +220,16 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.showStatusBar = !m.showStatusBar m.layout(m.terminalWidth, m.terminalHeight) return m, m.resizeChildren() + case "o": + if m.tree != nil && m.tree.selectedNode != nil { + c := exec.Command("micro", m.tree.selectedNode.path) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + c.Stderr = os.Stderr + return m, tea.ExecProcess(c, func(err error) tea.Msg { + return loadNote{path: m.tree.selectedNode.path, force: true} + }) + } } var cmds []tea.Cmd diff --git a/notes.go b/notes.go index d836d32..3170fa5 100644 --- a/notes.go +++ b/notes.go @@ -56,7 +56,8 @@ type NoteView struct { // ================== messages =================== type loadNote struct { - path string + path string + force bool } type loadedNote struct { @@ -157,7 +158,7 @@ func (m *NoteView) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd case loadNote: - if m.path == msg.path { + if m.path == msg.path && !msg.force { return m, nil //noop } m.path = msg.path