You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
It's not an issue per se and it's probably by design but I was wondering why adding an atomic block on the first line would leave this line empty and create the block on the next line. This makes it impossible to add media as the first block in the editor. I checked the Notes app and it has the same behaviour so I guess the code example is not really needed.
easybird, panddr, blackcater, igr-santos, tonygentilcore and 13 more
The main reason is that managing selection around media blocks was a pain. :) Since I didn't have a good way to "select" the atomic block or force a new block above it, my workaround was to always include a block above the inserted media.
If you really want to eliminate that and you have a good solution in your UI to insert a block above the atomic block, you could use Modifier to strip the block out before passing the EditorState back to your top-level component.
Ideally, the work that @ianstormtaylor and others are doing will help establish good patterns or APIs for selectable atomic blocks. With this, we could get rid of this workaround and allow the developer to manage selection, cursor behavior, and insertion.
Sorry not to have a better answer for this yet! :)
alexeygolev, easybird, blackcater, rpmonteiro and henrikhaugboelledaryn-k, craftedpixels, chrisrobbins, matveeva-as, jonatron and 1 moreSyMind, LittleBlackER and jonatron
This is still something that I'm struggling to figure out properly. I've been trying to add atomic blocks, but there is always a space before and after them.
There is no way for me to remove those spaces without deleting the atomic block if the block is on the edge of the editor, and even when they are not on the edge and I'd like to just delete those empty spaces to move text closer to my atomic block (lets say the block is an image) - the atomic block gets deleted unless I place the cursor on that empty line and press the delete key (for the bottom space).
If I ever want two atomic blocks to sit one on top of the other, its pretty much impossible with the way the editor is now - and I haven't found the SelectionState and Modified APIs very intuitive to learn, but I'm giving them a shot.
I feel like there should be an easy way to make atomic blocks undeletable within the editor - and then do an intentional delete on them with their key or something when you would like to, because currently the editing experience while using them is very fickle and it feels a little hacky trying to format the content the way I'd like (and especially for users who don't know all the tricks I can't imagine how frustrating they might find it).
PendletonJones, bunterWolf, jakoblo, irishbryan, jonzlin95 and 15 more
Perhaps you can get some inspiration from DraftJS Plugins? The focus plugin shows a nice way of interacting with atomic blocks.
This suggests a way of inserting new atomic blocks after existing ones when there are no new lines: the user focuses the atomic block and can then insert a new atomic block (e.g. by pressing a toolbar button) after it.
As for inserting new (non-atomic) blocks before, between or after atomic blocks, we use the following strategy:
If there are two atomic blocks in succession, focus the first one and press the enter key to insert an empty paragraph between the blocks.
If the first block in the editor is atomic, focus it and press the up arrow to insert an empty paragraph before it.
If the last block in the editor is atomic, focus it and press the down arrow (or enter key) to insert an empty paragraph after it.
@lukephills I should mention that we are (in our project) not using Draft Plugins. So the strategy I outlined is how we deal with atomic blocks, not how Draft Plugins does it.
Activity
hellendag commentedon Apr 20, 2016
The main reason is that managing selection around media blocks was a pain. :) Since I didn't have a good way to "select" the
atomic
block or force a new block above it, my workaround was to always include a block above the inserted media.If you really want to eliminate that and you have a good solution in your UI to insert a block above the
atomic
block, you could useModifier
to strip the block out before passing theEditorState
back to your top-level component.Ideally, the work that @ianstormtaylor and others are doing will help establish good patterns or APIs for selectable
atomic
blocks. With this, we could get rid of this workaround and allow the developer to manage selection, cursor behavior, and insertion.Sorry not to have a better answer for this yet! :)
lostpebble commentedon Feb 2, 2017
This is still something that I'm struggling to figure out properly. I've been trying to add atomic blocks, but there is always a space before and after them.
There is no way for me to remove those spaces without deleting the atomic block if the block is on the edge of the editor, and even when they are not on the edge and I'd like to just delete those empty spaces to move text closer to my atomic block (lets say the block is an image) - the atomic block gets deleted unless I place the cursor on that empty line and press the delete key (for the bottom space).
If I ever want two atomic blocks to sit one on top of the other, its pretty much impossible with the way the editor is now - and I haven't found the SelectionState and Modified APIs very intuitive to learn, but I'm giving them a shot.
I feel like there should be an easy way to make atomic blocks undeletable within the editor - and then do an intentional delete on them with their key or something when you would like to, because currently the editing experience while using them is very fickle and it feels a little hacky trying to format the content the way I'd like (and especially for users who don't know all the tricks I can't imagine how frustrating they might find it).
parris commentedon May 12, 2017
I'm going to bump this topic. Does anyone have ideas/strategies about how to add new blocks after existing blocks when there are no new lines?
robbertbrak commentedon May 12, 2017
Perhaps you can get some inspiration from DraftJS Plugins? The focus plugin shows a nice way of interacting with atomic blocks.
This suggests a way of inserting new atomic blocks after existing ones when there are no new lines: the user focuses the atomic block and can then insert a new atomic block (e.g. by pressing a toolbar button) after it.
As for inserting new (non-atomic) blocks before, between or after atomic blocks, we use the following strategy:
Does that help?
parris commentedon May 12, 2017
@robbertbrak yea thanks! Great example plugin and the strategy was helpful too.
lukephills commentedon May 15, 2017
@robbertbrak In the example focusing the coloured block and pressing enter breaks the editor.
robbertbrak commentedon May 16, 2017
@lukephills I should mention that we are (in our project) not using Draft Plugins. So the strategy I outlined is how we deal with atomic blocks, not how Draft Plugins does it.
sandywk commentedon Aug 24, 2018
Are there any available solutions now?
unstyled, 1
atomic) instead of one atomic #1985daryn-k commentedon Mar 24, 2019
After entire 3 years no improvements so far, lol
SyMind commentedon Mar 30, 2020
lol, 4 years ago.
chshouyu commentedon Jan 4, 2021
lol, almost 5 years ago.
nhanthanh93 commentedon Aug 6, 2021
lol, same
xu1718191411 commentedon Feb 9, 2022
Good luck, 6 years.
niuyuping commentedon Oct 10, 2022
almost 7 years