Skip to content

Commit

Permalink
Add option to open slide in editor
Browse files Browse the repository at this point in the history
This allows the user to edit the currently open slide with the command
ctrl+o. Must be a session in tmux. Currently only opens it in vim, but
I'll add more so that you can change to an editor of choice in a config
file.
  • Loading branch information
waelmahrous committed Oct 30, 2024
1 parent c6eea33 commit c17753c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -177,6 +178,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
case "ctrl+c", "q":
return m, tea.Quit
case "ctrl+o":
// Opens the current slide in vim
err := m.openNewWindow()
if err != nil {
return m, nil
}
default:
newState := navigation.Navigate(navigation.State{
Buffer: m.buffer,
Expand Down Expand Up @@ -314,3 +321,9 @@ func (m *Model) SetPage(page int) {
func (m *Model) Pages() []string {
return m.Slides
}

// Opens the current slide as a split window in tmux.
func (m *Model) openNewWindow() error {
cmd := exec.Command("tmux", "split-window", "-h", "vim", m.FileName)
return cmd.Start()
}

0 comments on commit c17753c

Please sign in to comment.