Skip to content

Fix description of several Range methods#38518

Merged
wbamberg merged 6 commits intomdn:mainfrom
Josh-Cena:fix-range
Mar 20, 2025
Merged

Fix description of several Range methods#38518
wbamberg merged 6 commits intomdn:mainfrom
Josh-Cena:fix-range

Conversation

@Josh-Cena Josh-Cena requested a review from a team as a code owner March 7, 2025 20:04
@Josh-Cena Josh-Cena requested review from wbamberg and removed request for a team March 7, 2025 20:04
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Mar 7, 2025
_sourceRange_ to the start boundary-point of `Range`.

- `sourceRange`
- : A constant describing the comparison method. Note that the constant names are backwards relative to what actually get compared: the `compareBoundaryPoints()` method compares `this` to `otherRange` (where `-1` means before and `1` means after), but the constant names are written as "`otherRange` to `this`".
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I find this a very confusing sentence!

One problem is that "comparing A to B" and "comparing B to A" are the same (to me) unless you insist that -1 must mean "before" and 1 must mean "after". So it hurts my brain to read "it compares A to B, not B to A".

I honestly think it would be better just to omit the sentence.

I like the use of this and otherRange in the bullets, I think that helps a lot.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"-1 means before, 1 means after" is an established convention. You see that in String.localeCompare and the comparator function of sort. Also in general "compare A to B" means "return A - B` for some abstract notion of subtraction.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm just telling you how this sentence reads to me, as a non-expert but not completely ignorant reader. Telling me it should make sense to me doesn't affect that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think if you want to say something about this, it would be better to put it alongside the return value (so it doesn't anticipate), and put it in a note, and say something like:

Note that it is a common convention for APIs that compare A to B to return -1 if A is before B, and 1 if A is after B, but this API reverses that convention.

For example, END_TO_START compares the end of otherRange to the start of this range, but it returns -1 if the start of this range is before the end of otherRange.

But I think it's as good or better just to be as clear as possible about what this specific API does, and not waste cognitive effort on what it doesn't do.

Comment on lines +17 to +21
deleteContents() returns:

<p>para</p><p>graph 3</p>
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is a nice example (and maybe worth keeping anyway) but it would be even better to update the current terrible example (and even better if it were a live sample).

@Josh-Cena Josh-Cena requested a review from wbamberg March 20, 2025 06:18
});
```

{{EmbedLiveSample("using_deletecontents", "", "150")}}
Copy link
Copy Markdown
Collaborator

@wbamberg wbamberg Mar 20, 2025

Choose a reason for hiding this comment

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

I think this needs a "Reset" button (https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Page_structures/Live_samples#displaying_a_reset_button) because it's a destructive change. And it would be nice if it logged innerHTML (https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Page_structures/Live_samples#displaying_a_single_entry_log) instead of making me use the devtools.

I actually see some behaviour I don't understand here. If I select some of p1, all of p2, and some of p3:

Screen Shot 2025-03-20 at 12 33 27 PM

...then delete:

Screen Shot 2025-03-20 at 12 34 04 PM

...then I see what I expect in the devtools:

Screen Shot 2025-03-20 at 12 34 36 PM

If I then select everything that's left:

Screen Shot 2025-03-20 at 12 35 00 PM

...and delete, then it's all gone:

Screen Shot 2025-03-20 at 12 35 35 PM

...but the devtools still shows the old DOM:

Screen Shot 2025-03-20 at 12 36 21 PM

devtools bug?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Update, yes, probably Firefox devtools bug. This doesn't happen in Chrome.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@wbamberg I originally had the capability of printing innerHTML, but (a) I'd rather encourage people to inspect DOM and keep the live sample seem more plausible (it currently resembles a real text editor) (b) the more markup there is, the more stuff there is to delete, and the UX may become more confusing (for example, if you print the inner HTML of the whole document, then the next time it's going to print itself; if you wrap these three elements inside a container, then it's possible to delete that container via the button, and then you may run into an error).

Copy link
Copy Markdown
Collaborator

@wbamberg wbamberg Mar 20, 2025

Choose a reason for hiding this comment

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

yes, it's a fair point, it also occurred to me that you would want to wrap the paragraphs in a container and then the user might delete it.

@Josh-Cena Josh-Cena requested a review from a team as a code owner March 20, 2025 20:15
@Josh-Cena Josh-Cena removed the request for review from a team March 20, 2025 20:17
@Josh-Cena
Copy link
Copy Markdown
Member Author

For some reason, the reset button doesn't work—the writing guide one doesn't work either. I don't want to implement a more complicated reset though, like actually re-inserting the DOM.

@wbamberg
Copy link
Copy Markdown
Collaborator

For some reason, the reset button doesn't work—the writing guide one doesn't work either. I don't want to implement a more complicated reset though, like actually re-inserting the DOM.

The writing guide one works for me in Firefox and Chrome (Chrome is very slow of course but that just seems to be the normal UX these days).

@wbamberg
Copy link
Copy Markdown
Collaborator

For some reason, the reset button doesn't work—the writing guide one doesn't work either. I don't want to implement a more complicated reset though, like actually re-inserting the DOM.

The writing guide one works for me in Firefox and Chrome (Chrome is very slow of course but that just seems to be the normal UX these days).

Though I suppose if it takes several seconds to work it's not really usable anyway. Ugh.

In that case tbh you might was well make it a static sample. It's pretty frustrating deleting bits of the content and then having to reload the page if you want to try again.

@Josh-Cena
Copy link
Copy Markdown
Member Author

I don't mind it being laggy on Chrome. I tried and it works well on both Firefox and Safari anyway. I can just actually refresh the whole page if I want to reset.

Copy link
Copy Markdown
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

👍 thanks for your patience!

@wbamberg wbamberg merged commit 2c0de98 into mdn:main Mar 20, 2025
8 checks passed
@Josh-Cena Josh-Cena deleted the fix-range branch March 20, 2025 23:17
wbamberg added a commit to wbamberg/content that referenced this pull request Apr 4, 2025
* upstream/main: (172 commits)
  chore: improve code style guide (mdn#38715)
  fix: typo on `Error.isError()` page (mdn#38754)
  plural consistency (mdn#38747)
  fix: auto-cleanup by bot (mdn#38695)
  Synchronize with BCD v5.7.4 (mdn#38709)
  Add docs for JS self-profiling API (mdn#37796)
  Better SameSite docs (mdn#38710)
  Added missing explanation for Array Literals (mdn#38745)
  Add a page on CSRF (mdn#38151)
  Fix description of several Range methods (mdn#38518)
  Remove extraneous span (mdn#38696)
  Add a definition for media containers, improve how the media files are defined and Remove wrong information (mdn#38721)
  Move visited selector guide to CSS selectors module (mdn#38642)
  Make JSON learning article more technically precise (mdn#38644)
  Make translate3d() interactive example code valid (mdn#38647)
  Clarity on Safari support for custom elements (mdn#38727)
  feat(css): Link to learning doc about text direction (mdn#38719)
  Fix typo (mdn#38739)
  move guide to module: inline formatting context (mdn#38637)
  Fix CSS pseudo-class lists (mdn#38576)
  ...
cssinate pushed a commit to cssinate/content that referenced this pull request Apr 11, 2025
* Fix description of several Range methods

* Apply suggestions from code review

Co-authored-by: wbamberg <will@bootbonnet.ca>

* Update index.md

* Better example

* Update files/en-us/web/api/range/compareboundarypoints/index.md

* Add a reset button

---------

Co-authored-by: wbamberg <will@bootbonnet.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

3 participants