r-wasm/quarto-live

Execute only the selected parts of the code block

tmieno2 opened this issue · 1 comments

It would be great to be able to run only the selected parts of the code.

This can be useful for a number of reasons. For example, you may look at mtcars to see what other variables it has without deleting all the other codes. You may want to run only plot(fit) without displaying summary(fit) without removing summary(fit) from the console.

fit = lm(mpg ~ am, data = mtcars)
summary(fit)
plot(fit)

This is possible in quarto-webr, and I found myself (and students) using this feature a lot when I teach.

Sounds good! If you or others have ideas on the best workflow and/or shortcuts for students and readers, please feel free to chip in here.

@coatless's extension handles this well, and I think we can copy the approach here in the first pass. IIUC the rules would be:

  • Clicking "Run code" always runs the entire block.
  • "Shift-Enter" also always runs the entire block.
  • Without code highlighted hitting "Ctrl/Cmd-Enter" runs the current line and drops the cursor down a line.
  • Selecting code and hitting "Ctrl/Cmd-Enter" partially executes only the highlighted code, and keeps the currently selected code.