Skip to content

Commit

Permalink
Let double ctrl-space both export and open Markdown documents
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jan 26, 2025
1 parent a780a54 commit f7202c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
25 changes: 5 additions & 20 deletions v2/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,6 @@ func (e *Editor) GenerateBuildCommand(c *vt100.Canvas, tty *vt100.TTY, filename
// Returns a status message and then true if an action was performed and another true if compilation/testing worked out.
// Will also return the executable output file, if available after compilation.
func (e *Editor) BuildOrExport(tty *vt100.TTY, c *vt100.Canvas, status *StatusBar) (string, error) {
// Build or export in the background
background := e.mode == mode.Markdown

// Clear the status messages, if we have a status bar
if status != nil && c != nil {
status.ClearAll(c, false)
Expand Down Expand Up @@ -600,16 +597,9 @@ func (e *Editor) BuildOrExport(tty *vt100.TTY, c *vt100.Canvas, status *StatusBa
return outputFilename, cmd.Run()
case mode.Markdown:
htmlFilename := strings.ReplaceAll(filepath.Base(sourceFilename), ".", "_") + ".html"
if background {
go func() {
_ = e.exportMarkdownHTML(c, status, htmlFilename)
}()
} else {
if err := e.exportMarkdownHTML(c, status, htmlFilename); err != nil {
return htmlFilename, err
}
}
// the exportPandoc function handles it's own status output
go func() {
_ = e.exportMarkdownHTML(c, status, htmlFilename)
}()
return htmlFilename, nil
case mode.Lua:
if e.LuaLoveOrLovr() {
Expand Down Expand Up @@ -1164,12 +1154,7 @@ func (e *Editor) BuildOrExport(tty *vt100.TTY, c *vt100.Canvas, status *StatusBa
}

// Build starts a build and is typically triggered from either ctrl-space or the o menu
func (e *Editor) Build(c *vt100.Canvas, status *StatusBar, tty *vt100.TTY, alsoRun, markdownDoubleSpacePrevention bool) {
// Enable only. e.runAfterBuild is set to false elsewhere.
if alsoRun {
e.runAfterBuild = true
}

func (e *Editor) Build(c *vt100.Canvas, status *StatusBar, tty *vt100.TTY) {
// If the file is empty, there is nothing to build
if e.Empty() {
status.ClearAll(c, false)
Expand Down Expand Up @@ -1242,7 +1227,7 @@ func (e *Editor) Build(c *vt100.Canvas, status *StatusBar, tty *vt100.TTY, alsoR
e.redraw.Store(false)

// Require a double ctrl-space when exporting Markdown to HTML, because it is so easy to press by accident
if markdownDoubleSpacePrevention && (e.mode == mode.Markdown && !alsoRun) {
if e.mode == mode.Markdown && !e.runAfterBuild {
return
}

Expand Down
4 changes: 2 additions & 2 deletions v2/cmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func (e *Editor) CommandMenu(c *vt100.Canvas, tty *vt100.TTY, status *StatusBar,
}
}
actions.Add(menuItemText, func() {
const markdownDoubleSpacePrevention = false
e.Build(c, status, tty, alsoRun, markdownDoubleSpacePrevention)
e.runAfterBuild = alsoRun
e.Build(c, status, tty)
})
}

Expand Down
7 changes: 2 additions & 5 deletions v2/keyloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,11 @@ func Loop(tty *vt100.TTY, fnord FilenameOrData, lineNumber LineNumber, colNumber
quitToNroff(tty, pwd, c.W(), c.H())
}
}
case mode.Markdown:
e.ToggleCheckboxCurrentLine()
default:
regularEditingRightNow = false
// Then build, and run if ctrl-space was double-tapped
var alsoRun = kh.DoubleTapped("c:0")
const markdownDoubleSpacePrevention = true
e.Build(c, status, tty, alsoRun, markdownDoubleSpacePrevention)
e.runAfterBuild = kh.DoubleTapped("c:0")
e.Build(c, status, tty)
e.redrawCursor.Store(true)
regularEditingRightNow = true
}
Expand Down
2 changes: 2 additions & 0 deletions v2/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (e *Editor) Run() (string, bool, error) {
} else {
cmd = exec.Command("xdg-open", pdfFilename)
}
case mode.Markdown:
cmd = exec.Command("algernon", "-m", sourceFilename)
case mode.Lua:
if e.LuaLove() {
const macLovePath = "/Applications/love.app/Contents/MacOS/love"
Expand Down

0 comments on commit f7202c3

Please sign in to comment.