Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve a DOM point from Slate point: {"path":[0,0],"offset":3} when programmatically removing content #4564

Open
Torvin opened this issue Oct 1, 2021 · 3 comments · May be fixed by #5407
Labels

Comments

@Torvin
Copy link

Torvin commented Oct 1, 2021

Description
I want to clear textarea on Enter. When I do so, slate throws an error:
Cannot resolve a DOM point from Slate point: {"path":[0,0],"offset":3}

Recording
slate

Sandbox
https://codesandbox.io/s/slate-0-5x-forked-kr8sc?file=/src/App.tsx

Steps
To reproduce the behavior:

  1. Type something in the editor
  2. Press Enter
  3. Error is thrown

Expectation
I shouldn't get an error. I'm guessing it tries to preserve caret position across updates and fails because the new content is shorter.

Environment

  • Slate Version: slate@0.66.5, slate-react@0.66.4
  • Operating System: Windows 10
  • Browser: Chrome 94.0.4606.61
@Torvin Torvin added the bug label Oct 1, 2021
@imdbsd
Copy link
Contributor

imdbsd commented Oct 3, 2021

i need to reset the position of the caret to the start of the editor in my editor. something like this

 if (e.key === "Enter") {
      e.preventDefault();
      Transforms.select(editor, Editor.start(editor, []));
      setContent([
        {
          type: 'paragraph',
          children: [{ text: '' }]
        }
      ]);
    }

@kGe-z
Copy link

kGe-z commented Dec 9, 2021

you can try it

function onKeyDown(e: React.KeyboardEvent) {
    const { selection } = editor;

    if (e.key === "Enter" && selection) {
      const path = selection.anchor.path;

      Transforms.select(editor, path.slice(0, path.length - 1));
      Transforms.delete(editor);

      e.preventDefault();
    }
 }

@tamilvendhank-helptap
Copy link

@kGe-z, you nailed it. Thanks!

@zbeyens zbeyens linked a pull request Apr 27, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants