From 49512217d618d692e0580a56e99273dd86c9ddc1 Mon Sep 17 00:00:00 2001 From: George Stagg Date: Tue, 27 Feb 2024 14:37:02 +0000 Subject: [PATCH] Source temporary file when running code in Editor (#362) * Source temporary file when running code in Editor * Update NEWS.md --- NEWS.md | 4 +++- src/repl/components/Editor.tsx | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2aa3c019..75886581 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/src/repl/components/Editor.tsx b/src/repl/components/Editor.tsx index 3bdcfdd2..37ac31ee 100644 --- a/src/repl/components/Editor.tsx +++ b/src/repl/components/Editor.tsx @@ -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]); @@ -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 = React.useCallback(() => {