mirror of
https://github.com/pyscript/pyscript.git
synced 2026-03-06 06:38:39 -05:00
committed by
GitHub
parent
ee345a5206
commit
5086c23d47
@@ -48,9 +48,12 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
|
||||
const pySrc = htmlDecode(this.innerHTML).trim();
|
||||
this.innerHTML = '';
|
||||
this.editor = this.makeEditor(pySrc);
|
||||
const boxDiv = this.makeBoxDiv();
|
||||
const shadowRoot = $('.py-repl-editor > div', boxDiv).attachShadow({ mode: 'open' });
|
||||
// avoid inheriting styles from the outer component
|
||||
shadowRoot.innerHTML = `<style> :host { all: initial; }</style>`;
|
||||
this.appendChild(boxDiv);
|
||||
this.editor = this.makeEditor(pySrc, shadowRoot);
|
||||
this.editor.focus();
|
||||
logger.debug(`element ${this.id} successfully connected`);
|
||||
}
|
||||
@@ -80,7 +83,7 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
const cmcontentElement = $('div[class="cm-content"]', this);
|
||||
const cmcontentElement = $('div.cm-content', this.editor.dom);
|
||||
const { lastElementChild } = cmcontentElement;
|
||||
cmcontentElement.replaceChildren(lastElementChild);
|
||||
lastElementChild.textContent = await response.text();
|
||||
@@ -93,7 +96,7 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
|
||||
/** Create and configure the codemirror editor
|
||||
*/
|
||||
makeEditor(pySrc: string): EditorView {
|
||||
makeEditor(pySrc: string, parent: ShadowRoot): EditorView {
|
||||
const languageConf = new Compartment();
|
||||
const extensions = [
|
||||
indentUnit.of(' '),
|
||||
@@ -113,6 +116,7 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
return new EditorView({
|
||||
doc: pySrc,
|
||||
extensions,
|
||||
parent,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,10 +142,16 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
const editorDiv = document.createElement('div');
|
||||
editorDiv.className = 'py-repl-editor';
|
||||
editorDiv.setAttribute('aria-label', 'Python Script Area');
|
||||
editorDiv.appendChild(this.editor.dom);
|
||||
|
||||
const runButton = this.makeRunButton();
|
||||
editorDiv.appendChild(runButton);
|
||||
const editorShadowContainer = document.createElement('div');
|
||||
|
||||
// avoid outer elements intercepting key events (reveal as example)
|
||||
editorShadowContainer.addEventListener('keydown', event => {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
editorDiv.append(editorShadowContainer, runButton);
|
||||
|
||||
return editorDiv;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class TestPyRepl(PyScriptTest):
|
||||
"""
|
||||
)
|
||||
py_repl = self.page.locator("py-repl")
|
||||
src = py_repl.inner_text()
|
||||
src = py_repl.locator("div.cm-content").inner_text()
|
||||
assert "print('hello from py-repl')" in src
|
||||
py_repl.locator("button").click()
|
||||
self.page.wait_for_selector("py-terminal")
|
||||
@@ -601,7 +601,7 @@ class TestPyRepl(PyScriptTest):
|
||||
assert self.console.info.lines[-1] == successMsg
|
||||
|
||||
py_repl = self.page.locator("py-repl")
|
||||
code = py_repl.inner_text()
|
||||
code = py_repl.locator("div.cm-content").inner_text()
|
||||
assert "print('1')" in code
|
||||
|
||||
@skip_worker("TIMEOUT")
|
||||
|
||||
Reference in New Issue
Block a user