Skip to content

Commit

Permalink
fix(caret): right-arrow on last non-default block (#1416)
Browse files Browse the repository at this point in the history
* fix(caret): last non-default block navigation won't craete a new block untill reaching the end

* reuse variable
  • Loading branch information
neSpecc authored Nov 21, 2020
1 parent bfd0ea1 commit e319e04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- `Fix` - add getter keyword to `block.mergeable` method [#1415](https://github.com/codex-team/editor.js/issues/1415).
- `Fix` — Fix problem with entering to Editor.js by Tab key [#1393](https://github.com/codex-team/editor.js/issues/1393)
- `Fix` - Sanitize pasted block data [#1396](https://github.com/codex-team/editor.js/issues/1396).

- `Fix` - Unnecessary block creation after arrow navigation at last non-default block[#1414](https://github.com/codex-team/editor.js/issues/1414)

### 2.19

Expand Down
14 changes: 11 additions & 3 deletions src/components/modules/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,22 @@ export default class Caret extends Module {
const { BlockManager, Tools } = this.Editor;
const { currentBlock, nextContentfulBlock } = BlockManager;
const { nextInput } = currentBlock;
const isAtEnd = this.isAtEnd;

let nextBlock = nextContentfulBlock;

if (!nextBlock && !nextInput) {
/**
* If there is no nextBlock and currentBlock is default, do not navigate
* This code allows to exit from the last non-initial tool:
* https://github.com/codex-team/editor.js/issues/1103
*/
if (Tools.isDefault(currentBlock.tool)) {

/**
* 1. If there is a last block and it is default, do nothing
* 2. If there is a last block and it is non-default --> and caret not at the end <--, do nothing
* (https://github.com/codex-team/editor.js/issues/1414)
*/
if (Tools.isDefault(currentBlock.tool) || !isAtEnd) {
return false;
}

Expand All @@ -414,7 +422,7 @@ export default class Caret extends Module {
nextBlock = BlockManager.insertAtEnd();
}

if (force || this.isAtEnd) {
if (force || isAtEnd) {
/** If next Tool`s input exists, focus on it. Otherwise set caret to the next Block */
if (!nextInput) {
this.setToBlock(nextBlock, this.positions.START);
Expand Down

0 comments on commit e319e04

Please sign in to comment.