Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Empty line on adding atomic block  #327

@alexeygolev

Description

@alexeygolev

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.

Activity

hellendag

hellendag commented on Apr 20, 2016

@hellendag

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! :)

lostpebble

lostpebble commented on Feb 2, 2017

@lostpebble

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

parris commented on May 12, 2017

@parris

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

robbertbrak commented on May 12, 2017

@robbertbrak
Contributor

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.

Does that help?

parris

parris commented on May 12, 2017

@parris

@robbertbrak yea thanks! Great example plugin and the strategy was helpful too.

lukephills

lukephills commented on May 15, 2017

@lukephills

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.

@robbertbrak In the example focusing the coloured block and pressing enter breaks the editor.

robbertbrak

robbertbrak commented on May 16, 2017

@robbertbrak
Contributor

@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

sandywk commented on Aug 24, 2018

@sandywk

Are there any available solutions now?

daryn-k

daryn-k commented on Mar 24, 2019

@daryn-k

After entire 3 years no improvements so far, lol

SyMind

SyMind commented on Mar 30, 2020

@SyMind

lol, 4 years ago.

chshouyu

chshouyu commented on Jan 4, 2021

@chshouyu

lol, almost 5 years ago.

nhanthanh93

nhanthanh93 commented on Aug 6, 2021

@nhanthanh93

lol, same

xu1718191411

xu1718191411 commented on Feb 9, 2022

@xu1718191411

Good luck, 6 years.

niuyuping

niuyuping commented on Oct 10, 2022

@niuyuping

almost 7 years

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @parris@robbertbrak@chshouyu@alexeygolev@lostpebble

        Issue actions

          Empty line on adding atomic block · Issue #327 · facebookarchive/draft-js