Skip to content

Commit

Permalink
Source temporary file when running code in Editor (#362)
Browse files Browse the repository at this point in the history
* Source temporary file when running code in Editor

* Update NEWS.md
  • Loading branch information
georgestagg authored Feb 27, 2024
1 parent 7089386 commit 4951221
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

## Bug Fixes

* Fix showing content of lazy loaded files in webR demo app editor component #320
* Fix showing content of lazy loaded files in webR demo app editor component (#320).

* Contents of the code editor in the webR REPL application is now sourced as a temporary file, allowing for input longer than the default R console input buffer length (#326).

* R error conditions raised during evaluation of an `RCall` or `RFunction` object are now re-thrown as JavaScript exceptions.

Expand Down
12 changes: 10 additions & 2 deletions src/repl/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ export function Editor({
code = utils.getCurrentLineText(editorView);
utils.moveCursorToNextLine(editorView);
}
webR.writeConsole(code);

const codeArray = new TextEncoder().encode(code);
webR.FS.writeFile('/tmp/.webRtmp-source', codeArray).then(()=>{
webR.writeConsole("source('/tmp/.webRtmp-source', echo = TRUE)");
});
};
}, [editorView]);

Expand All @@ -214,7 +218,11 @@ export function Editor({
syncActiveFileState();
const code = editorView.state.doc.toString();
terminalInterface.write('\x1b[2K\r');
webR.writeConsole(code);

const codeArray = new TextEncoder().encode(code);
webR.FS.writeFile('/tmp/.webRtmp-source', codeArray).then(()=>{
webR.writeConsole("source('/tmp/.webRtmp-source', echo = TRUE)");
});
}, [syncActiveFileState, editorView]);

const saveFile: React.MouseEventHandler<HTMLButtonElement> = React.useCallback(() => {
Expand Down

0 comments on commit 4951221

Please sign in to comment.