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

[Bug] Unnecessary block creation after arrow navigation at last non-default block #1414

Closed
neSpecc opened this issue Nov 5, 2020 · 0 comments · Fixed by #1416
Closed

[Bug] Unnecessary block creation after arrow navigation at last non-default block #1414

neSpecc opened this issue Nov 5, 2020 · 0 comments · Fixed by #1416
Assignees
Labels

Comments

@neSpecc
Copy link
Member

neSpecc commented Nov 5, 2020

In the 2.18 by closing this issue the caret.navigateNext() method was improved. Now if we press right or down key at the last non-default block, editor will create the new default block at the bottom to allow navigation to it:

image

But there are some problems with the current implementation:

  1. The new block will be created even if we press right with caret set not at the end of block content.
  2. BlockManager.insertAtEnd(); will call .insert() without any params, and as a result, the currentBlockIndex will wrongly be incremented.
public insert({
    tool = this.config.defaultBlock,
    data = {},
    index,
    needToFocus = true,
    replace = false,
  }: {
    tool?: string;
    data?: BlockToolData;
    index?: number;
    needToFocus?: boolean;
    replace?: boolean;
  } = {}): Block {
    let newIndex = index;

    if (newIndex === undefined) {
      newIndex = this.currentBlockIndex + (replace ? 0 : 1);  // <--- here is the +1
    }

    // ...
  }

Steps to reproduce:

  1. Go to example.html
  2. Clear all the content
  3. Open DevTools / Elements
  4. Find and open .codex-editor__redactor to see a list of .ce-block elements
  5. Click on the last block
  6. Create a Header or any other non-default block and type some text
  7. Place the caret at the center of this block.
  8. Press Right

You will see that the new .ce-block will be created below our block.

<div class="codex-editor__redactor" style="padding-bottom: 300px;">
  <div class="ce-block"></div> <!-- the block where we pressed Right not at the end -->
  <div class="ce-block"></div> <!-- wrongly created block -->
</div>

Expected behavior:

  1. The new block should be created only when we're pressing Right or Down at the end of the last non-default block.
  2. The currentBlockIndex should not be changed when we're pressing Right or Down not at the end of the last non-default block.

Editor.js version:

2.19

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.

1 participant