Hidden nodes (blocks and inlines)
See original GitHub issueThis 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:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top GitHub Comments
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. 😃
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?