tc39 / ecmarkup

An HTML superset/Markdown subset source format for ECMAScript and related specifications
https://tc39.es/ecmarkup/
MIT License
216 stars 62 forks source link

Add indentation to hidden counter text #604

Closed gibson042 closed 2 weeks ago

gibson042 commented 3 weeks ago

This results in better copied text, e.g.

b. Set length to length + 1.
c. Let weight be GetWeight of node.
d. If length = 10**9 or weight > 2**(length + 1), then
   i. NOTE: This is an out-of-bounds state.
   ii. If ignoreErrors is not true, then
       1. Throw a RangeError exception.
   iii. Set hadError to true.

rather than

b. Set length to length + 1.
c. Let weight be GetWeight of node.
d. If length = 10**9 or weight > 2**(length + 1), then
i. NOTE: This is an out-of-bounds state.
ii. If ignoreErrors is not true, then
1. Throw a RangeError exception.
iii. Set hadError to true.
bakkot commented 3 weeks ago

Thanks! I don't like that the whitespace is included even if just copying a single line, though, as one does fairly often when writing an implementation which closely adheres to the spec text. I'm a bit hesitant to mess with the copy event, but it's probably appropriate here.

gibson042 commented 3 weeks ago

OK, that makes sense. Done.

bakkot commented 3 weeks ago

I think that logic is broken in Chrome and Safari, which give slightly different selection ranges when triple-clicking.

I can try to fix it later if you haven't gotten to it first.

gibson042 commented 2 weeks ago

@bakkot Updated; please retest and let me know about any issues you encounter.

bakkot commented 2 weeks ago

Looks like it works for steps with substeps, but not steps without. Specifically, triple-clicking on the "This is an out-of-bounds state" line in the docs ends up with the following tree structure in domRoot, which doesn't trigger the conditions you're checking for:

Screenshot 2024-08-27 at 12 10 26 PM
gibson042 commented 2 weeks ago

Thanks for the detail. Fixed.