abelsj60 / lexical-401

An unauthorized library of Lexical nodes, plugins, and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG: Text doubling when using toolbar!

abelsj60 opened this issue · comments

  1. Write some code.
  2. Place the cursor inside it.
  3. Use the Toolbar to convert it to a code block
  4. Behold: The code is converted, but the original plain text is doubled beneath it!
  5. (Markdown shortcut does not do this — i.e., triple backtick plus language name plus space: ```js ...

This is a regression!

I haven't seen this behavior in awhile. Self: Track it down and fix it. May also be causing follow-on effects... 

All set.

The real problem was that I hadn't properly updated the Toolbar component in the sandbox. It was using the old wrapNodes function. It should instead be doing something like this:

      editor.update(() => {
        const selection = $getSelection();
        const codeNode = $createLinedCodeNode();

        if ($isRangeSelection(selection)) {
          codeNode.insertInto(selection);
        }
      });

I ended up gutting the Toolbar component in CodeSandbox while trying to get my bearings. You'll now see a single button to convert editor text to the LinedCodeNode. There's no button to convert it back, or controls to use the test editor generally.

For purposes of demonstration, this is probably OK.

I'm closing this issue now with a personal reminder to return to the lingering markdown issue, which I'd forgotten.