fix: Backspaces do not work when the code block contains initial data.
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.
@neSpecc
Yes, I added it.
When will this pull request be reviewed? It's a pretty annoying bug.
Hey, @yosipy would you please, add a test for this case?
I've been busy lately and don't have time to fix the code.