diff --git a/.gitignore b/.gitignore
index 8db40be2..9a66cbf2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
/.luarc.json
+*_files
+webr-worker.js
+webr-serviceworker.js
+webr-*.html
diff --git a/_extensions/webr/_extension.yml b/_extensions/webr/_extension.yml
index 168939c4..e4174f25 100644
--- a/_extensions/webr/_extension.yml
+++ b/_extensions/webr/_extension.yml
@@ -1,7 +1,7 @@
name: webr
title: Embedded webr code cells
author: James Joseph Balamuta
-version: 0.3.1
+version: 0.3.2
quarto-required: ">=1.2.198"
contributes:
filters:
diff --git a/_extensions/webr/monaco-editor-init.html b/_extensions/webr/monaco-editor-init.html
new file mode 100644
index 00000000..84746ac6
--- /dev/null
+++ b/_extensions/webr/monaco-editor-init.html
@@ -0,0 +1,10 @@
+
+
\ No newline at end of file
diff --git a/_extensions/webr/webr-editor.html b/_extensions/webr/webr-editor.html
index 506240c8..3f741ab7 100644
--- a/_extensions/webr/webr-editor.html
+++ b/_extensions/webr/webr-editor.html
@@ -30,20 +30,6 @@
hideCursorInOverviewRuler: true // Remove cursor indictor in right hand side scroll bar
});
- // Add a keydown event listener for Shift+Enter using the addCommand method
- editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
- // Code to run when Shift+Enter is pressed
- executeCode(editor.getValue());
- });
-
- // Add a keydown event listener for Ctrl+Enter to run selected code
- editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, function () {
- // 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);
- });
-
// Dynamically modify the height of the editor window if new lines are added.
let ignoreEvent = false;
const updateHeight = () => {
@@ -61,6 +47,32 @@
}
};
+ // Registry of keyboard shortcuts that should be re-added to each editor window
+ // when focus changes.
+ const addWebRKeyboardShortCutCommands = () => {
+ // Add a keydown event listener for Shift+Enter to run all code in cell
+ editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, () => {
+
+ // Retrieve all text inside the editor
+ executeCode(editor.getValue());
+ });
+
+ // 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);
+ });
+ }
+
+ // Register an on focus event handler for when a code cell is selected to update
+ // what keyboard shortcut commands should work.
+ // This is a workaround to fix a regression that happened with multiple
+ // editor windows since Monaco 0.32.0
+ // https://github.com/microsoft/monaco-editor/issues/2947
+ editor.onDidFocusEditorText(addWebRKeyboardShortCutCommands);
+
// Register an on change event for when new code is added to the editor window
editor.onDidContentSizeChange(updateHeight);
diff --git a/_extensions/webr/webr-init.html b/_extensions/webr/webr-init.html
index 8bebb656..487f9327 100644
--- a/_extensions/webr/webr-init.html
+++ b/_extensions/webr/webr-init.html
@@ -1,4 +1,5 @@
-
+
+
-
-