From f7202c3532492c647d86b75bb66494c593138ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Sun, 26 Jan 2025 13:15:56 +0100 Subject: [PATCH] Let double ctrl-space both export and open Markdown documents --- v2/build.go | 25 +++++-------------------- v2/cmenu.go | 4 ++-- v2/keyloop.go | 7 ++----- v2/run.go | 2 ++ 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/v2/build.go b/v2/build.go index a29d855e..f439875b 100644 --- a/v2/build.go +++ b/v2/build.go @@ -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) @@ -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() { @@ -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) @@ -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 } diff --git a/v2/cmenu.go b/v2/cmenu.go index ac67958c..a23f5708 100644 --- a/v2/cmenu.go +++ b/v2/cmenu.go @@ -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) }) } diff --git a/v2/keyloop.go b/v2/keyloop.go index 36de0ecd..cf279531 100644 --- a/v2/keyloop.go +++ b/v2/keyloop.go @@ -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 } diff --git a/v2/run.go b/v2/run.go index 5c7b4e55..caebb238 100644 --- a/v2/run.go +++ b/v2/run.go @@ -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"