Re: [whatwg/dom] Add PlainTextRange interface (PR #1404)

@annevk commented on this pull request.



> @@ -9892,6 +9892,144 @@ and {{Range/getBoundingClientRect()}} methods are defined in other specification
 [[CSSOM-VIEW]]
 
 
+<h3 id=interface-plaintext-range>Interface {{PlainTextRange}}</h3>
+
+<pre class=idl>
+[Exposed=Window]
+interface PlainTextRange : AbstractRange {

I think this is the wrong name now the idea is to no longer tie it to text.

> + returns a rectangle of zero width whose height equals the line height at the caret position. If the
+ host has computed <code>display</code> of <code>none</code> or is not <a>connected</a>, returns a
+ rectangle with zero width and height.
+</dl>
+
+<p>A {{PlainTextRange}} is a range whose <a>boundary points</a> are defined as offsets in a
+host-defined <a href="#plaintext-range-string">plain text range string</a> rather than in the
+<a>node tree</a>. It has no associated container node; its {{AbstractRange/startContainer}} and
+{{AbstractRange/endContainer}} getters return null, and its {{AbstractRange/startOffset}} and
+{{AbstractRange/endOffset}} getters return indices into that string.</p>
+
+<p>A {{PlainTextRange}} has associated state:</p>
+
+<ul>
+ <li><p><dfn export for=PlainTextRange id=plaintext-range-host>host</dfn> (null or an
+ {{Element}}).</p></li>

Why do we need this? The host should be in charge of allocating these at which point these don't really need to have a host owner.

> +{{AbstractRange/endContainer}} getters return null, and its {{AbstractRange/startOffset}} and
+{{AbstractRange/endOffset}} getters return indices into that string.</p>
+
+<p>A {{PlainTextRange}} has associated state:</p>
+
+<ul>
+ <li><p><dfn export for=PlainTextRange id=plaintext-range-host>host</dfn> (null or an
+ {{Element}}).</p></li>
+ <li><p><dfn export for=PlainTextRange id=plaintext-range-start>start offset</dfn> (a non-negative
+ integer).</p></li>
+ <li><p><dfn export for=PlainTextRange id=plaintext-range-end>end offset</dfn> (a non-negative
+ integer).</p></li>
+</ul>
+
+<p>The {{AbstractRange/startContainer}} getter steps for {{PlainTextRange}} objects are to return
+null.</p>

This doesn't work. You need to adjust `AbstractRange` getter (including IDL) to allow for returning null here. And we do still want to store the actual start/end container so `AbstractRange` will need to support some kind of "is opaque" switch.

> + <li><p>Insertion at the start boundary: A non-{{AbstractRange/collapsed}} range expands to include
+ the new text. A collapsed range moves after the insertion.</p></li>
+ <li><p>Insertion at the end boundary: A non-collapsed range does not expand to include the new
+ text. A collapsed range moves after the insertion.</p></li>
+ <li><p>Clamping and collapse: Offsets are clamped to the current string length. If the
+ {{AbstractRange/startOffset}} would exceed the {{AbstractRange/endOffset}}, set the end to the
+ start.</p></li>
+</ul>
+
+<p class=note>Specifications that define elements which <a>support plain text ranges</a> (such as
+the HTML Standard for text controls) must normatively define when a {{PlainTextRange}} is created,
+how it is associated with a host, when its host becomes null, and when its boundary points are
+updated using the rules above.</p>
+
+<p>The <dfn export for=PlainTextRange id=dom-plaintext-range-stringifier>stringification
+behavior</dfn> must run these steps:</p>

As I mentioned in https://github.com/whatwg/html/issues/11478#issuecomment-3531228837 I don't think exposing `toString()` is correct at this level.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1404#pullrequestreview-3550425870
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1404/review/3550425870@github.com>

Received on Monday, 8 December 2025 07:15:17 UTC