Skip to content

Add selection range checks to updateSelection, updateText and EditContext constructor. - #144

Open
ltenmoz wants to merge 1 commit into
w3c:gh-pagesfrom
ltenmoz:editcontext-check-selection-and-text-ranges
Open

Add selection range checks to updateSelection, updateText and EditContext constructor.#144
ltenmoz wants to merge 1 commit into
w3c:gh-pagesfrom
ltenmoz:editcontext-check-selection-and-text-ranges

Conversation

@ltenmoz

@ltenmoz ltenmoz commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #88. I'm hoping it's not too late to change this. :)

For normative changes, the following tasks have been completed:

@ltenmoz
ltenmoz force-pushed the editcontext-check-selection-and-text-ranges branch from 72105f8 to b6986db Compare July 28, 2026 20:36
@ltenmoz

ltenmoz commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Hmm actually, checking the bounds in updateText() breaks the Monaco code editor. It seems they are doing updateText(0, Infinity, newText) which I suppose is slightly more convenient than updateText(0, editContext.text.length, newText). So perhaps it's best to leave that out. With the other changes, Monaco, CodeMirror, and Google Docs all seem to work fine, which are all the EditContext users we discovered searching HTTPArchive. So I think it should be safe to make this change (let's hope…)

@ltenmoz ltenmoz changed the title Add range checks to updateSelection(), updateText(), and EditContext constructor Add selection range checks to updateSelection, updateText and EditContext constructor. Jul 28, 2026
Comment thread index.html
<ol>
<li>
If |rangeStart| is greater than the length of [=text=],
set |rangeStart| to the length of [=text=].

@ltenmoz ltenmoz Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, let's add steps here to make it clear that it's intended behaviour that these can be > text.length

@ltenmoz ltenmoz added the Agenda+ Queue this item for discussion at the next WG meeting label Aug 6, 2026
@smaug----

Copy link
Copy Markdown

@dandclark

@dandclark

Copy link
Copy Markdown
Contributor

We'll need to add some telemetry to Chromium to verify to what degree this will run into compatibility problems. If that data shows it can be done, I'd be in favor of this. If Monaco turns out to be the only ones who'd have problems with the change to updateText, we could potentially reach out to them to see if they'd be willing to make a change. It'd be nice to have updateText be consistent with the rest.

@ltenmoz

ltenmoz commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Yes I agree it'd be better to have updateText throw as well, maybe it is worth reaching out to Monaco (although I suspect it might take a while for enough sites to update it that we could safely make the change…)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Agenda+ Queue this item for discussion at the next WG meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should selection start/end be limited to the size of the text?

3 participants