Expose py-editor code content read/write (#2087)

* Expose py-editor code content read/write

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andrea Giammarchi
2024-06-03 12:32:54 +02:00
committed by GitHub
parent cb9ee6f7e2
commit 2ac5ca79d7
3 changed files with 85 additions and 67 deletions

View File

@@ -184,6 +184,21 @@ const init = async (script, type, interpreter) => {
let target;
defineProperties(script, {
target: { get: () => target },
code: {
get: () => context.pySrc,
set: (insert) => {
if (isSetup) return;
editor.update([
editor.state.update({
changes: {
from: 0,
to: editor.state.doc.length,
insert,
},
}),
]);
},
},
process: {
/**
* Simulate a setup node overriding the source to evaluate.