Skip to content

Add 'Run code block under cursor' command#452

Open
nelsonlove wants to merge 7 commits into
twibiral:masterfrom
nelsonlove:run-block-under-cursor
Open

Add 'Run code block under cursor' command#452
nelsonlove wants to merge 7 commits into
twibiral:masterfrom
nelsonlove:run-block-under-cursor

Conversation

@nelsonlove

Copy link
Copy Markdown

Summary

An editor command (like org-babel's C-c C-c / Jupyter's Ctrl-Enter): put the cursor anywhere inside a fenced code block in source mode or live preview and run it — no need to switch to reading view or hunt for the run button (which doesn't render in live preview while the cursor is inside the block). Output is saved into the note below the block via persistent output.

Builds on #449 (whose commits are included) — the buffered Vault.process persistent output is what lets this work without any rendered DOM.

Implementation

  • runBlockUnderCursor.ts: tracks fence state from the top of the note to the cursor to find the enclosing block (handles the cursor sitting on either fence line), resolves the language from the fence info string (including run- prefixes and {...} args), and dispatches through the existing handleExecution with a detached outputter element.
  • handleExecution and CodeBlockContext are exported from RunButton.ts; no behavior change for the button path.
  • Registered via editorCallback, so the command only offers itself when an editor is active.
  • If Persistent Output is disabled, the command explains (via Notice) that it needs it — there is nowhere visible to stream output when running from the editor.

Testing

  • npm run build passes
  • Verified in a live vault: cursor inside a lisp block in source mode → command executes it and writes/replaces the ```output block below; works with session (interactive) executors and the run- prefix; Notices for cursor-outside-block, unterminated fences, and non-executable languages

🤖 Generated with Claude Code

nelsonlove and others added 7 commits July 11, 2026 06:29
…en the code block can't be located

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… render, not per execution

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ion start

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… completion

Locates the block via the post-processor's getSectionInfo when available,
falling back to matching the block's source text. Works in reading view,
live preview, and for run- prefixed blocks; re-running replaces the output
block instead of appending.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…output; hide live element once saved

Reading view used to hide saved ```output blocks via CSS (a workaround for
the old streaming write). Now that output is written once on completion,
the saved block IS the result display — render it in all views, insert it
with a blank line after the code block, and hide the ephemeral on-screen
output element once the note has been updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Runs the fenced block containing the editor cursor (like org-babel's
C-c C-c) through the normal execution pipeline with a detached outputter;
results are saved into the note via persistent output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant