Text.decorations assumes that ranges in decorations[] are for current node
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What’s the current behavior?
Ranges returned from decorate function are always applied to current node even if they do not intersect.
In this example there is only one decoration which should only apply to the first text node, since decoration path is [0, 0]
Sandbox: https://codesandbox.io/s/slate-reproductions-ch9e4 Slate: 0.57 Browser: Chrome OS: Windows
What’s the expected behavior?
If the decoration range is outside current node, it should not be applied.
Comments
This issue seems to be related to #3352 . Based on my dive into slate code I see two possible solutions:
- Adjust how slate-react
Children
components treats result ofdecorate()
. It looks likedecorations
prop is filtered usingRange.intersection
, butdecorate()
array is not. Mergingds
withdecorations
and then filtering should solve this issue. - Make
Text.decorations
, which cuts up a node into leaves, aware of node’s range. This should make filter onChildren
component unnecessary.
It seems to me that second option is a more generic solution.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
text-decoration - CSS: Cascading Style Sheets - MDN Web Docs
Text decorations are drawn across descendant text elements. This means that if an element specifies a text decoration, then a child element can' ......
Read more >Node position & node decoration - Discuss - ProseMirror
My use case is I need to decorate a specific node that I know the path ... I tried so many thing but...
Read more >Understanding Decorators in Eclipse
As the name suggests, text label decorators are decorations on resource labels and image decorators are decorations on icon images. The resource name...
Read more >CSS Text Decoration Module Level 4 - W3C
Since line decorations can span elements with varying font sizes and vertical alignments, the best position for a line decoration is not ...
Read more >Rebuilding a Range with a Node, startOffset and endOffset
/** * */ buildRange: function(text, startOffset, endOffset){ var node = this.getNodeByText(text); // get the Node by its contents var range = ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ianstormtaylor Let me know which solution you prefer, or how you would like to handle this, and I’ll do a PR.
When I implemented annotations, I was surprised that the ranges I returned were being applied in weird places, until I started filtering them based on the path of the node supplied to the
decorate
function:(The collapsed check is because I do some different rendering on collapsed ranges.)
I may not be understanding this bug completely, but is my approach not also a workaround or am I going to get bitten down the road?