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.

Proposal for better ergonomics when rendering marks

See original GitHub issue

I’m facing a pain point with mark rendering in slate-react, and I know how I wish things worked, but I’m not sure what would actually be needed implementation-wise to pull it off.

Here’s a contrived example of what I’m going for.

Imagine wanting to linkify all text that matches a URL pattern, but you also want to (again, contrived) make the domain bold:

screenshot from 2018-12-01 21-57-33

Using an inline isn’t great because it’s cumbersome to validate and restructure on every match and mismatch, and you still want the text to behave like normal text with cursor, focus, and selection.

Marks are a good fit, and especially decorations. You can just decorate with a link mark and a bold mark for each match with a single regex.

Imagine that the link mark has some styling to make the link red on hover. You’d want it to look like this:

screenshot from 2018-12-01 21-57-56

Unforunately, because of the way marks are rendered, if you happen to hover over the domain portion, it would look like this:

screenshot from 2018-12-01 21-58-44

And if you hovered the scheme, it would look like this:

screenshot from 2018-12-01 21-59-26

This is because mark rendering actually breaks up overlapping marks into a series of smaller contiguous marks.

Ie. instead of rendering mark components like this:

<Link>https://<Bold>www.google.com</Bold>/webhp</Link>

They’re rendered like this:

<Link>https://</Link><Link><Bold>www.google.com</Bold></Link><Link>/webhp</Link>

I worked around this previously with a hack in my mark components themselves, making the assumption that children of mark components would always be a string. I’d just create a single Link component for the whole match and manipulate its children into several strings wrapped in <span>s, making the appropriate section bold.

However, after recent changes, leaves render text wrapped in a <span>, meaning my brittle hack to manipulate strings can’t operate (slate-react expects the leaf span, with its attributes, to wrap the final text).

I think the changes helped a lot with focus behavior, but I can’t find a good way to pull off the desired behavior. I think what I really want is just more expected component rendering for marks, so marks that overlap would render components like this:

<Link>https://<Bold>www.google.com</Bold>/webhp</Link>

Is this feasible somehow? Any other approaches that would work well?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
alanchrtcommented, Dec 7, 2018

Sounds good! I do think isAtomic is the right approach. In the short term, however, I decided it would be good for the health of my app to break as many decorations as possible down into smaller marks, then refactor everything to use pure CSS and just render children as-is. In the end, the only one that really didn’t fit well (and where isAtomic would help) is the Stars example above. For now, I have a glorious CSS hack to style the last star darker, which will someday be my shame when another developer uncovers it…

Will see if I can get a chance to poke at atomic marks sometime soon! I’m sure it will bite me again.

0reactions
ianstormtaylorcommented, Dec 5, 2019

@timothyarmes correctly pointed out that this is not solved. The leaves themselves are still broken up so there’s no guarantee the link remains intact. My bad!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ergonomics Program Management Guidelines For ...
Key elements of a good work practice program for ergonomics include proper work techniques, employee conditioning, regular monitoring, feedback, maintenance, ...
Read more >
A Contribution to Workplace Ergonomics Evaluation Using ...
deals with the proposal of methodology for ergonomics eval- ... realize that the better the environment is adapted to the needs. of the...
Read more >
request for proposals rfp #10621 for ergonomic services
The L3 evaluation is designed to manage the injury more ... 7.2.1 Five (5) sets of the proposal package (one original proposal marked...
Read more >
Comments on the "Ergonomics Program Standard" Proposed ...
Modern epidemiology renders the. Proposed Ergonomie Standard anti- quated at best, and likely to be harm- ful. It also suggests that programs.
Read more >
Workplace Ergonomic Training and Consulting Services
PURPOSE OF THIS REQUEST FOR PROPOSALS . ... of records in order to render, in good faith, the disclosure required by ... clearly...
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