editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

fix: Backspaces do not work when the code block contains initial data.

Open yosipy opened this issue 1 year ago • 4 comments

fix: https://github.com/editor-js/code/issues/75

https://github.com/editor-js/code/issues/67

When we add a new code block, backspace works.

https://github.com/user-attachments/assets/975796e4-58d2-4082-8b32-b6ee6b26d5d5

However, when updating a code block with initial data, backspaces do not work.

      const editorConfig = {
        data: {
          blocks: [
            
            {
              type: "code",
              data: {
                code: 'console.log("ssss")',
              },
            },
          ],

https://github.com/user-attachments/assets/9bfecc31-bfb3-4a7d-8c16-9c47e1c42234

Cause

The value of the argument input of function isCaretAtStartOfInput (src/components/utils/caret.ts) is as follows when there is no initial value.

<textarea class="ce-code__textarea cdx-input" placeholder="Enter a code" data-empty="false"></textarea>

When there is an initial value, the value is as follows.

<textarea class="ce-code__textarea cdx-input" placeholder="Enter a code" data-empty="false">console.log("ssss")</textarea>

firstNode is the string 'console.log(“ssss”)' and isCaretAtStartOfInput()==true.

Solution

When the argument input is native input, firstNode is assigned input.

yosipy avatar Oct 04 '24 23:10 yosipy

@neSpecc

Yes, I added it.

yosipy avatar Oct 10 '24 10:10 yosipy

When will this pull request be reviewed? It's a pretty annoying bug.

CasFreriks avatar Oct 29 '24 16:10 CasFreriks

Hey, @yosipy would you please, add a test for this case?

neSpecc avatar Jan 11 '25 13:01 neSpecc

I've been busy lately and don't have time to fix the code.

yosipy avatar Mar 02 '25 09:03 yosipy