Skip to content

Empty link inserted after press Enter key behind a link #3772

Closed

Description

@shomukai

Do you want to request a feature or report a bug?

Report a bug

What's the current behavior?

Slate: 0.58.4
Link: https://www.slatejs.org/examples/links
OS: Mac OS Catalina 10.15.4 (19E287)
Browser: Chrome Version 83.0.4103.116 (Official Build) (64-bit)

After inserted a link, press enter key immediately, and empty link is inserted as well.
captured

Screen Shot 2020-07-08 at 5 31 57 pm

What's the expected behavior?

Should not insert empty link. (Doesn't happen in older version 0.47)

Activity

  1. oeroche commented on Jul 12, 2020

    @oeroche

    I face the same idsue, quite annoying as it affects not only links but all inline nodes... it leads to a weird behaviour. I tried to solve the issue by introducing a new normalization rule but in the end it blocks the first line break...

  2. pirtlj commented on Oct 6, 2020

    @pirtlj

    I am facing the same issue in 0.59.0

  3. jcdelmas commented on Mar 26, 2021

    @jcdelmas

    I've fixed this issue with the following code:

    editor.insertBreak = () => {
      const [selectedElement, path] = Editor.parent(editor, editor.selection);
    
      if (selectedElement.type === 'link') {
        const endPoint = Range.end(editor.selection);
        const [selectedLeaf] = Editor.node(editor, endPoint);
        if (selectedLeaf.text.length === endPoint.offset) {
          if (Range.isExpanded(editor.selection)) {
            Transforms.delete(editor);
          }
          Transforms.select(editor, Path.next(path));
        }
      }
      insertBreak();
    };
    

    It moves the selection out of the link before the line break.

    Does it work for you?

  4. dylans commented on Oct 12, 2026

    @dylans
    Collaborator

    Fixed by #6202: pressing Enter at the end of a link now starts the next paragraph outside the link. Please reopen if you still get an empty link.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions