- From: Justin Fagnani <notifications@github.com>
- Date: Tue, 15 Apr 2025 17:34:09 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1369/2807866341@github.com>
justinfagnani left a comment (whatwg/dom#1369) @robbiespeed yes, this would address a more narrow set of use cases than #736, namely mutating contiguous ranges of nodes. It's a simpler proposal because it doesn't introduce a new DOM interface, construct new novel tree structures, or affect parsing at all with special handling for certain comments. Those things could certainly still be added - these proposals aren't mutually exclusive. `insertRangeBefore()` is a good idea. You can accomplish it with `extractRange()` and `insertBefore()` with the resulting DocumentFragment, but `insertRangeBefore()` would bypass creating DocumentFragment instance. The reason I went with the operations working exclusive of the start and end nodes is to make it easy to work with the contents of ranges bracketed by marker nodes, which is how a lot of library code works. Clearing a dynamic expression would look something like ```ts container.deleteRange(expr.start, expr.end); ``` which would preserve the marker nodes. If the operation worked on start and end inclusive, then you would have to write something like: ```ts if (expr.start.nextSibling !== expr.end) { container.deleteRange(expr.start.nextSibling, expr.end.previousSibling); } ``` Sometimes you want to move a range and its marker nodes, so with exclusive ranges you need write: ```ts const fragment = container.extractRange(expr.start.previousSibling, expr.end.nextSibling); ``` But this is safe because if either previous and next siblings are null, that means the marker is the first or last child respectively, and extracting to the beginning or end of the child list is correct. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/1369#issuecomment-2807866341 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/dom/issues/1369/2807866341@github.com>
Received on Wednesday, 16 April 2025 00:34:13 UTC