HS: select returns selected text (+1 test)
Runtime gains hs-get-selection: prefers window.__test_selection stash, falls back to real getSelection().toString(). Compiler rewrites `(ref "selection")` to `(hs-get-selection)`. Generator detects the createRange + setStart/setEnd + addRange block and emits a single host-set! on __test_selection with the text slice; sidesteps the need for a fully propagating DOM range/text-node mock. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1142,6 +1142,30 @@ def parse_dev_body(body, elements, var_names):
|
||||
ops.append(f'(if (dom-has-class? {target} "{cls}") (dom-remove-class {target} "{cls}") (dom-add-class {target} "{cls}"))')
|
||||
continue
|
||||
|
||||
# evaluate(() => { var range = document.createRange();
|
||||
# var textNode = document.getElementById(ID).firstChild;
|
||||
# range.setStart(textNode, N); range.setEnd(textNode, M);
|
||||
# window.getSelection().addRange(range); })
|
||||
# -> set window.__test_selection to text slice
|
||||
m = re.search(
|
||||
r"document\.createRange\(\)[\s\S]*?document\.getElementById\(\s*['\"]([\w-]+)['\"]\s*\)[\s\S]*?setStart\([^,]+,\s*(\d+)\s*\)[\s\S]*?setEnd\([^,]+,\s*(\d+)\s*\)",
|
||||
stmt_na,
|
||||
)
|
||||
if m and seen_html:
|
||||
el_id = m.group(1)
|
||||
start = int(m.group(2))
|
||||
end = int(m.group(3))
|
||||
# Find the element whose id matches, pull its inner text/HTML
|
||||
selected_text = None
|
||||
for el in elements:
|
||||
if el.get('id') == el_id:
|
||||
txt = el.get('inner') or ''
|
||||
selected_text = txt[start:end]
|
||||
break
|
||||
if selected_text is not None:
|
||||
ops.append(f'(host-set! (host-global "window") "__test_selection" "{selected_text}")')
|
||||
continue
|
||||
|
||||
if not seen_html:
|
||||
continue
|
||||
if add_action(stmt_na):
|
||||
|
||||
Reference in New Issue
Block a user