question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Text.decorations assumes that ranges in decorations[] are for current node

See original GitHub issue

Do 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:

  1. Adjust how slate-react Children components treats result of decorate(). It looks like decorations prop is filtered using Range.intersection, but decorate() array is not. Merging ds with decorations and then filtering should solve this issue.
  2. Make Text.decorations, which cuts up a node into leaves, aware of node’s range. This should make filter on Children component unnecessary.

It seems to me that second option is a more generic solution.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
BetaAIcommented, Dec 23, 2019

@ianstormtaylor Let me know which solution you prefer, or how you would like to handle this, and I’ll do a PR.

0reactions
zwilycommented, Mar 22, 2021

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:

  ([, path], editor) => {
    let ranges = [];
    for (let [, ann] of Object.entries(editor.annotations)) {
      if (
        !Range.isCollapsed(ann) &&
        Path.compare(ann.anchor.path, path) === 0
      ) {
        ranges.push(ann);
      } else if (Range.isCollapsed(ann) && Path.equals(ann.anchor.path, path)) {
        ranges.push({
          ...ann,
          collapsed: true,
        });
      }
    }

    return ranges;
  }

(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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found