fix(caret): right-arrow on last non-default block (#1416)

* fix(caret): last non-default block navigation won't craete a new block untill reaching the end

* reuse variable
This commit is contained in:
Peter Savchenko 2020-11-21 16:44:20 +03:00 committed by GitHub
parent bfd0ea10ea
commit e319e04350
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

2
dist/editor.js vendored

File diff suppressed because one or more lines are too long

View file

@ -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

View file

@ -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;
}
@ -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);