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.

Impossible to create overlapping marks/decorations which have the same semantic meaning but different metadata

See original GitHub issue

Do you want to request a feature or report a bug?

It is a feature that went missing from 0.47, so bug?

What’s the current behavior?

It is impossible to create intersecting custom marks/decorations. In this case intersecting text highlights. Before: slate-1 After: slate-0 It seems that this is due to removal of Mark interface. Custom attributes are now simply merged in to the leaf, which makes it impossible to have 2 marks/decorations with the same semantic (highlight) but different data (color). Under new model there can be only one. This might also pose problems for plugins that implement different marks/decorations which could have property collisions.

Sandbox: https://codesandbox.io/s/slate-reproductions-4i770 Add highlights by selecting text and using Ctrl+(r|g|b) Slate: 0.57 Browser: Chrome OS: Windows

What’s the expected behavior?

Ability to have mark/decoration intersections. Under current model I do not see any straightforward way to implement this. If I missed something, please let me know.

Comments

Potential solution is modifying how mark/decoration data is applied to the leaf. Currently this is done by Object.assign function. If a mark/decoration, which now is an object, is replaced by a function that is used instead of Object.assign, this will give user fine grain control over how mark/decoration data is assembled on a leaf. Additionally, this will be an opt-in functionality, since user will need to explicitly implement it, so it will not change functionality of existing code.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
BetaAIcommented, Dec 24, 2019

@Immortalin Since bold and italic are orthogonal marks, it is possible to do nesting. Here is an example: https://codesandbox.io/s/slate-reproductions-k6mpd (Ctrl+b to bold, Ctrl+i to italicize) If you are coming from pre 0.50, main thing to note is that before slate used to do nested mark wrapping for you (not 100% sure, but it did for Annotation). This is something that you have to do yourself now. All slate does is merge mark/decoration data into leaf object. Take a look at renderLeaf in the sandbox (lines 18 - 24)

0reactions
thesunnycommented, Apr 23, 2021

FYI, you can still implement marks yourself as an Array. There is nothing stopping you from having your text object defined as something like:

const myText = {
  text: "Hello World",
  marks: ['strong', 'em']
}

That said, it’s pretty easy to extract the marks from a text object and iterate over them because text objects have exactly one property that isn’t a mark:

const { text, ...marks } = myText

And then you iterate over marks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 1 - MPG.PuRe
This reveals how the early modern textbooks first amplified medieval scientific knowledge and only slowly began to support and spread the echoes of...
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