diff --git a/_extensions/webr/webr-context-interactive.html b/_extensions/webr/webr-context-interactive.html index 3f741ab7..eeb59943 100644 --- a/_extensions/webr/webr-context-interactive.html +++ b/_extensions/webr/webr-context-interactive.html @@ -47,6 +47,11 @@ } }; + // Helper function to check if selected text is empty + function isEmptyCodeText(selectedCodeText) { + return (selectedCodeText === null || selectedCodeText === undefined || selectedCodeText === ""); + } + // Registry of keyboard shortcuts that should be re-added to each editor window // when focus changes. const addWebRKeyboardShortCutCommands = () => { @@ -59,10 +64,38 @@ // Add a keydown event listener for CMD/Ctrl+Enter to run selected code editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => { + // Get the selected text from the editor const selectedText = editor.getModel().getValueInRange(editor.getSelection()); - // Code to run when Ctrl+Enter is pressed (run selected code) - executeCode(selectedText); + // Check if no code is selected + if (isEmptyCodeText(selectedText)) { + // Obtain the current cursor position + let currentPosition = editor.getPosition(); + // Retrieve the current line content + let currentLine = editor.getModel().getLineContent(currentPosition.lineNumber); + + // Propose a new position to move the cursor to + let newPosition = new monaco.Position(currentPosition.lineNumber + 1, 1); + + // Check if the new position is beyond the last line of the editor + if (newPosition.lineNumber > editor.getModel().getLineCount()) { + // Add a new line at the end of the editor + editor.executeEdits("addNewLine", [{ + range: new monaco.Range(newPosition.lineNumber, 1, newPosition.lineNumber, 1), + text: "\n", + forceMoveMarkers: true, + }]); + } + + // Run the entire line of code. + executeCode(currentLine); + + // Move cursor to new position + editor.setPosition(newPosition); + } else { + // Code to run when Ctrl+Enter is pressed with selected code + executeCode(selectedText); + } }); } diff --git a/docs/_quarto.yml b/docs/_quarto.yml index 740b3157..275fe722 100644 --- a/docs/_quarto.yml +++ b/docs/_quarto.yml @@ -4,7 +4,7 @@ project: - CNAME website: - title: "quarto-webr: A Quarto Extension for webR" + title: "quarto-webr" reader-mode: true repo-url: https://github.com/coatless/quarto-webr repo-actions: [edit, issue] @@ -35,8 +35,8 @@ website: text: README Example - href: webr-code-cell-demos.qmd text: Exploring Interactive Code Cells - - href: webr-community-example-gallery.qmd - text: Community Example Gallery + - href: webr-community-examples.qmd + text: Community Examples - section: "Deployment" contents: - href: webr-communication-channels.qmd diff --git a/docs/index.qmd b/docs/index.qmd index b9430977..ca8d212f 100644 --- a/docs/index.qmd +++ b/docs/index.qmd @@ -21,4 +21,4 @@ summary(model) At its core, the [quarto-webr extension](https://github.com/coatless/quarto-webr) is designed to empower you to run R code directly in your web browser using familiar reporting tools, all without the need for an external R server. Moreover, the extension abstracts away the need to know HTML or JavaScript to use webR. However, it's worth noting that you can also choose to unlock the full potential of webR and create more complex applications independently by directly using [webR's JavaScript API](https://docs.r-wasm.org/webr/latest/evaluating.html), granting you unparalleled freedom to harness the power of R in innovative ways. -With this in mind, let's dive in and kickstart your journey with interactive code cells by creating our very first [webR-powered Quarto document](webr-first-steps.qmd)! +With this in mind, let's dive in and kickstart your journey with interactive code cells by [creating our very first webR-powered Quarto document](webr-first-steps.qmd) or [exploring interactive code cells](webr-code-cell-demos.qmd)! diff --git a/docs/webr-community-example-gallery.qmd b/docs/webr-community-examples.qmd similarity index 74% rename from docs/webr-community-example-gallery.qmd rename to docs/webr-community-examples.qmd index bda8761f..544a667d 100644 --- a/docs/webr-community-example-gallery.qmd +++ b/docs/webr-community-examples.qmd @@ -1,5 +1,5 @@ --- -title: "Community Example Gallery" +title: "Community Examples" subtitle: "Explore Real-world Use Cases and Projects Using the `quarto-webr` Extension" date: "09-22-2023" date-modified: last-modified @@ -12,9 +12,9 @@ filters: Welcome to the Community Examples page for the `quarto-webr` extension. This section celebrates the diverse and innovative ways that members of our community are harnessing the power of the `quarto-webr` extension. These examples showcase real-world use cases, highlighting the extension's adaptability and functionality across various fields. You may also find references to examples from the [main webR project](https://webr.r-wasm.org/) here as well. -Explore the projects, applications, educational materials, and more created by fellow users. Gain inspiration from the community's contributions and discover how you can leverage the full potential of quarto-webr in your own work. Whether your interests lie in data analysis, interactive reports, or educational resources, you'll find valuable insights and ideas within the community's projects. +Explore the projects, applications, educational materials, and more created by fellow users. Gain inspiration from the community's contributions and discover how you can leverage the full potential of `quarto-webr` in your own work. Whether your interests lie in data analysis, interactive reports, or educational resources, you'll find valuable insights and ideas within the community's projects. -Do you have your own project or example that incorporates `quarto-webr`? We [invite you to contribute](https://github.com/coatless/quarto-webr/edit/main/docs/webr-community-example-gallery.qmd) to this growing collection of community-driven projects by submitting a [pull request](https://github.com/coatless/quarto-webr/edit/main/docs/webr-community-example-gallery.qmd) or [creating an issue](https://github.com/coatless/quarto-webr/issues/new?assignees=&labels=community-example&projects=&template=community-example.yml&title=%5BExample%5D%3A+). Your experiences and creativity can inspire others and promote collaboration within our community. Together, we can continue to expand the possibilities of `quarto-webr`. +Do you have your own project or example that incorporates `quarto-webr`? We invite you to contribute to this growing collection of community-driven projects by submitting a [pull request](https://github.com/coatless/quarto-webr/edit/main/docs/webr-community-examples.qmd) or [creating an issue](https://github.com/coatless/quarto-webr/issues/new?assignees=&labels=community-example&projects=&template=community-example.yml&title=%5BExample%5D%3A+). Your experiences and creativity can inspire others and promote collaboration within our community. Together, we can continue to expand the possibilities of `quarto-webr`. # Videos @@ -34,10 +34,13 @@ Do you have your own project or example that incorporates `quarto-webr`? We [inv - [George Stagg](https://gws.phd)'s talk on the [Magic with WebAssembly and webR](https://gws.quarto.pub/magic-with-wasm-and-webr/#/title-slide) mentioning `quarto-webr` as an easy onboarding option. Sep 20, 2023 @ posit::conf(2023) - [James Balamuta](http://thecoatlessprofessor.com/)'s talk on [Dynamic Interactions:Empowering Educators and Researchers with Interactive Quarto Documents Using webR](https://assets.thecoatlessprofessor.com/talks/quarto-webr-posit-conf-23-talk.pdf). Sep 19, 2023 @ posit::conf(2023) - [George Stagg](https://gws.phd)'s talk on the [Introduction to webR](https://gws.quarto.pub/introduction-to-webr-2023/#/title-slide) mentioning `quarto-webr` as an easy onboarding option. Sep 18, 2023 @ posit::conf(2023) -- [bob Rudis](https://rud.is/)' talk on [🕸️ Into the WebR-Verse](https://github.com/hrbrmstr/2023-nyr-webr) incorporating a demo of the `quarto-webr` extension. Jul 13 @ New York R Conference 2023 +- [Nicola Rennie](https://nrennie.rbind.io/)'s talk on [Teaching statistics interactively with webR](https://nrennie.rbind.io/talks/rss-conference-teaching-webr/). @ RSS International Conference 2023 + - [Slides](https://teaching-with-webr.netlify.app/#/title-slide) and [Source code](https://github.com/nrennie/teaching-with-webR) +- [bob Rudis](https://rud.is/)' talk on [🕸️ Into the WebR-Verse](https://github.com/hrbrmstr/2023-nyr-webr) incorporating a demo of the `quarto-webr` extension. Jul 13th, 2023 @ New York R Conference 2023 - [Video](https://www.youtube.com/watch?v=inpwcTUmBDY&list=PLlzRFZmxVl9RYNkA-lRUxloDYrd1Bhln9&index=8) and [Source code](https://github.com/hrbrmstr/2023-nyr-webr) - boB used a [cool trick to embed the demo](https://github.com/coatless/quarto-webr/issues/14#issuecomment-1634944155) in his revealjs slides. - [Maria Tackett](https://maria-tackett.netlify.app/)'s talk on [Using Quarto for Making and Organizing Teaching Materials](https://mine-cetinkaya-rundel.github.io/teach-with-quarto/talks/5-teaching-materials/) during the [Teaching (with) Quarto](https://mine-cetinkaya-rundel.github.io/teach-with-quarto/) Session. Aug 7, 2023 @ JSM 2023 + - [Slides](https://mine-cetinkaya-rundel.github.io/teach-with-quarto/talks/5-teaching-materials/) and [Source code](https://github.com/mine-cetinkaya-rundel/teach-with-quarto/tree/main/talks/5-teaching-materials) - [WebR Demo](https://maria.quarto.pub/webr-demo/) on [Quarto Pub](https://quarto.pub) # Textbooks @@ -52,12 +55,14 @@ Do you have your own project or example that incorporates `quarto-webr`? We [inv # Social media posts -- [Linh Nguyen](https://www.linkedin.com/in/nguyenllpsych)'s post on [LinkedIn](https://www.linkedin.com/posts/nguyenllpsych_positconf2023-activity-7111101659509899265-CTay?utm_source=share&utm_medium=member_desktop) describing how she used knowledge at posit::conf(2023) to convert existing R notes to use the `quarto-webr` extension. Sept 22, 2023 +- [Linh Nguyen](https://nguyenllpsych.github.io/)'s post on [LinkedIn](https://www.linkedin.com/posts/nguyenllpsych_positconf2023-activity-7111101659509899265-CTay?utm_source=share&utm_medium=member_desktop) and [Twitter](https://twitter.com/nguyenllpsych/status/1705357201400066141) describing how she used knowledge at posit::conf(2023) to convert existing R notes to use the `quarto-webr` extension. Sept 22, 2023 - [Joe Chelladurai](https://joechelladurai.com/) mentioning a [similiar integration on mastodon](https://mastodon.social/@joe_chelladurai@fosstodon.org/110699434655070719) for his newly developed [The School of Data](https://www.theschoolofdata.org/). Jul 11th, 2023 +- [Nicola Rennie](https://nrennie.rbind.io/)'s tweet showing [live coding with webR](https://twitter.com/nrennie35/status/1654509541499850752). May 5th, 2023 - [bob Rudis](https://rud.is/)' kind [praise](https://mastodon.social/@hrbrmstr/110130242863636605) of the extension. Apr 2nd, 2023 # Blog posts +- [Javier Orraca-Deatcu](https://www.javierorracadeatcu.com/)'s post titled [webR via Quarto Extensions](https://www.javierorracadeatcu.com/posts/2023-08-23-webr-via-quarto-extensions/). Aug 23rd, 2023. - [George Stagg](https://gws.phd/)'s mention of the extension in his [webR 0.2.0 announcement](https://www.tidyverse.org/blog/2023/08/webr-0-2-0/). Aug 8th, 2023. - [Ethan White](https://www.weecology.org/author/ethan-white/)'s use to create a [portal for Tidy Tuesday](https://tidytuesday.weecology.org/). May 2nd, 2023 - [Matt Dray](https://www.matt-dray.com/)'s post on [Playgrounds with WebR and Quarto](https://www.rostrum.blog/posts/2023-03-16-webr-quarto/). Mar 16th, 2023