question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

insertNodes with select:true puts the cursor *before* the new node

See original GitHub issue

Description A call to Slate.Transforms.insertNodes(..., { select: true }) should always put the cursor inside the new node. But under some conditions (minimal sandbox reproduction below), the cursor is placed BEFORE the new node. Reverting https://github.com/ianstormtaylor/slate/pull/4304 fixes this bug.

Recording

https://user-images.githubusercontent.com/166966/138719381-5fbf12d1-76a3-4109-816d-969ff8806c78.mp4

Sandbox https://codepen.io/jameshfisher/pen/gOxmWoJ

Steps To reproduce the behavior:

  1. Go to https://codepen.io/jameshfisher/pen/gOxmWoJ
  2. Put your cursor in the pink box.
  3. Hit return. This removes the pink box, inserts a new one in its place, and selects the new one. But from slate-react@0.66.4, the cursor is put BEFORE the new box.

Expectation A call to Slate.Transforms.insertNodes(..., { select: true }) should put the cursor inside the new node.

But with slate-react@0.66.4 and above, the cursor is placed BEFORE the new node.

Environment

Context

The feature I’m implementing is a Notion-style “commander”, where you type something like “/math”, hit return, and it executes some command, like inserting an inline math element.

This is probably related to https://github.com/ianstormtaylor/slate/issues/4601, another bug caused by https://github.com/ianstormtaylor/slate/pull/4304

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jameshfishercommented, Oct 25, 2021

@dylans would you also accept a PR that adds a rudimentary official example of implementing “slash commands”? I was again in the situation where I couldn’t demo this bug using official examples, and I suspect this “slash commands” feature is an increasingly common one …

1reaction
dylanscommented, Oct 25, 2021

I’m guessing this is also the source of #4611.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: In slate-react 0.66.4+, insertNodes with select:true puts the ...
This removes the pink box, inserts a new one in its place, and selects the new one. ... But from slate-react@0.66.4, the cursor...
Read more >
Problem to add a new block right after the current one
If there is no selection (you havent placed your cursor anywhere) then it will place this block Node Transforms insertNodes.
Read more >
Selecting a Block-Level Node after Insertion - Discuss
I've had to add the + 1 to the anchor so it would actually select the last image (and not the one before...
Read more >
Building A Rich Text Editor (WYSIWYG) - Smashing Magazine
We will use SlateJS to build the shell of the editor and then add a ... The common types of nodes that a...
Read more >
HTML Editor: Artifact [e4b7861598] - Martijn's Coding Corner
insertNode ( clone ); // Save the last element reference so we can make the ... document status by placing the cursor before...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found