Doc: What does hanging
mean?
#4244
-
QuestionFrom the source code and the documentation, I can't understand what "hanging" means. Could somebody explain? I think it would be nice to explain it somewhere in the documentation. Edit: The answer is: A range is hanging if it starts at the end of a node or ends at the start of a node. |
Beta Was this translation helpful? Give feedback.
Replies: 16 comments 4 replies
-
Hey @lcswillems, from the issue template:
(Or, you could restructure this as a documentation request!) |
Beta Was this translation helpful? Give feedback.
-
I have updated the issue. Why not allowing Github Discussions on this repo? The big advantage is that they will be indexed by Google. |
Beta Was this translation helpful? Give feedback.
-
That is a good suggestion. @CameronAckermanSEL, thoughts? |
Beta Was this translation helpful? Give feedback.
-
Its a fair point, however this has been a long standing request by Ian and it's really up to him to change it. That said, the request for documentation on what hanging means is a perfectly reasonable enhancement request for the documentation |
Beta Was this translation helpful? Give feedback.
-
Perhaps you know this, but I think @lcswillems means the relatively new Discussions feature, like for example, https://github.com/zeit/next.js/discussions. The concept didn't exist in Github until recently. They don't count as issues, and can be answered by anyone. Might help with some of the recurring questions we get in Slack about DOM selection, last focused position, how to match/nodes effectively etc. (I definitely agree we shouldn't have questions as issues here.) |
Beta Was this translation helpful? Give feedback.
-
Oh! I didn't know that feature was a thing! |
Beta Was this translation helpful? Give feedback.
-
@lcswillems Maybe we can guess the meaning of |
Beta Was this translation helpful? Give feedback.
-
I don't get it either... Is somebody able to explain this concept with a sentence? |
Beta Was this translation helpful? Give feedback.
-
UpdateFeb 23, 2022 See this slack convo between ianstormtaylor and Jason: #4852 The TL;DR is that unhanging the range only affects the end of the range and not the start (and this is intended behaviour). But for those who want to understand the problem more, continue reading below: From my experience, hanging means that the selection is on a node but hasn't really selected anything in the node. For example: Given this slate document:
It would render like so:
Now if we selected the "two":
We don't really have a guarantee of the selection's path and offset for the anchor and focus points. Let's go over the possible scenarios for
If you use Hehe, I came here looking for whether there was a bug with hanging selection and I ended up finding that someone has already created an issue and PR. Hope it gets merged soon! |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer! Now, I get it! A simple sentence would be: A range is hanging if it starts at the end of a node or ends at the start of a node. |
Beta Was this translation helpful? Give feedback.
-
Perhaps include a note about when/why this happens, why it matters, and when/why/how to fix it? |
Beta Was this translation helpful? Give feedback.
-
Hello! Wanted to point out that based on the implementation, neither offset can be non-zero. I think that means
? If it should be an or, I think the the code has a bug and should be if ((start.offset !== 0 && end.offset !== 0) || Range.isCollapsed(range)) { @ianstormtaylor does that sound right? |
Beta Was this translation helpful? Give feedback.
-
Also intrested here, does partially hanging (scenario 2 and 3) can defined as hanging? |
Beta Was this translation helpful? Give feedback.
-
Any information on how a hanging range can even be constructed? I can't replicate this behavior at all, although I now understand what a hanging range is. |
Beta Was this translation helpful? Give feedback.
-
It could be reproduced manually this way (probably it is not the only one case). const value = [
{ children: [{ text: 'first paragraph' }] }
{ children: [{ text: 'second paragraph' }] }
] If you do a triple click on the first paragraph you probably expect this selection: {
"anchor": { "path": [0, 0], "offset": 0 },
"focus": { "path": [0, 0], "offset": 15 }
} but you get this: {
"anchor": { "path": [0, 0], "offset": 0 },
"focus": { "path": [1, 0], "offset": 0 }
} So if you put the second selection to According to code it seems like it "unhangs" ranges only if both anchor and focus points have 0 offset. I found the example here: udecode/plate#200 |
Beta Was this translation helpful? Give feedback.
-
I thought I understood "hanging", but I am confused when I read the slate code, e.g. in
I thought that |
Beta Was this translation helpful? Give feedback.
Thank you for your answer! Now, I get it! A simple sentence would be:
A range is hanging if it starts at the end of a node or ends at the start of a node.