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.

Hidden nodes (blocks and inlines)

See original GitHub issue

This is a feature idea for hidden blocks/inlines as a first-class citizen.

I’m working on folding behavior in my editor. So, in some instances, certain chunks of the document should not be visible.

However, I’m struggling to find a way to implement this. Since Slate operates on the visible content, if the blocks are styled to not be displayed and the user operates on the surrounding area, the blocks can be easily deleted from the document in error. Or, if I style them to be rendered but not visible (absolutely positioned off-screen, for example), they still steal the selection when moving between lines.

If I create a fragment of the blocks and store it elsewhere when folded, then insert it back in when unfolded, I mess with the operation history, which is not ideal for collaborative editing.

So, my suggestion (which I would be willing to look into implementation details and maybe even take a stab at it) is to support an isHidden property on nodes that allows a node to be included in the document, but not rendered. I’m not sure if this would mess with selection, but I’d imagine it could function somewhat like isVoid?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
alanchrtcommented, Oct 10, 2017

Wellllllll, shoot. I did some testing to try to get a visual, and actually discovered Slate is doing all the right things under the hood for folding to work properly, with no accidentally destructive operations. Whenever performing operations around hidden blocks, they are actually treated as if they were still in the document like visible blocks. The data is right there, and I somehow completely missed it.

My problem was in the way I referenced blocks for unfolding… the fold/unfold UI was on a sibling block of the hidden block, so if the sibling relationship changed during an operation, then I wasn’t able to unfold the hidden block by referencing it as a sibling of the visible UI, and I mistook that for the hidden block being deleted (it’s not).

So, all that to say, there are a few tweaks I need to make to preserve references to hidden blocks properly, and a couple edge case behaviors I’d like to modify, but Slate is totally doing the expected thing and isn’t a part of the equation at all. In fact, I’m not building a code editor (Ace already got that one in the bag), but the folding behavior I have using Slate seems to already behave almost identical to folding in my code editor out of the box.

Thanks for the attention to this and sorry for the noise! Let me know if it’s still not clear, but it seems like Slate already supports hidden nodes. 😃

1reaction
YurkaninRyancommented, Oct 9, 2017

What would happen if you just set the content editable of all of those hidden blocks to false? and then with css made it so they couldn’t be selected?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cracking the CSS Display:inline, block, inline-block, none ...
In this article, we are going to perform a deep-dive maneuver to unravel the mystery behind the CSS display property.
Read more >
Why baseline of `inline-block` element with `overflow:hidden ...
The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow...
Read more >
Understanding CSS Display: None, Block, Inline and Inline ...
An explanation of the differences between display: none and visibility: hidden, understanding display: block, inline and inline-block.
Read more >
Difference between block elements and inline elements
So let us see the differences between the inline and block elements in HTML and the different frequently used inline and block HTML...
Read more >
Inline elements - HTML: HyperText Markup Language | MDN
In this article, we'll examine HTML inline-level elements and how they differ from block-level elements.
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