add open with micro

This commit is contained in:
2026-01-04 17:44:36 +00:00
parent 259645ec6e
commit f51c0b17c6
2 changed files with 18 additions and 2 deletions
+15
View File
@@ -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
+2 -1
View File
@@ -57,6 +57,7 @@ type NoteView struct {
// ================== messages ===================
type loadNote struct {
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