mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 15:45:47 +01:00
Set caret at the end if clicked outsite the block (#305)
* Set caret at last block or create new block at end * update comment * fix comments
This commit is contained in:
parent
29d2bae8ec
commit
4b1d9335b2
4 changed files with 36 additions and 3 deletions
|
|
@ -3788,6 +3788,24 @@ var BlockManager = function (_Module) {
|
|||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always inserts at the end
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'insertAtEnd',
|
||||
value: function insertAtEnd() {
|
||||
/**
|
||||
* Define new value for current block index
|
||||
*/
|
||||
this.currentBlockIndex = this.blocks.length - 1;
|
||||
|
||||
/**
|
||||
* Insert initial typed block
|
||||
*/
|
||||
this.insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two blocks
|
||||
* @param {Block} targetBlock - previous block will be append to this block
|
||||
|
|
@ -4522,7 +4540,7 @@ var Caret = function (_Module) {
|
|||
if (lastBlock.isEmpty) {
|
||||
this.setToBlock(lastBlock);
|
||||
} else {
|
||||
this.Editor.BlockManager.insert(this.config.initialBlock);
|
||||
this.Editor.BlockManager.insertAtEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -122,6 +122,21 @@ export default class BlockManager extends Module {
|
|||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always inserts at the end
|
||||
*/
|
||||
insertAtEnd() {
|
||||
/**
|
||||
* Define new value for current block index
|
||||
*/
|
||||
this.currentBlockIndex = this.blocks.length - 1;
|
||||
|
||||
/**
|
||||
* Insert initial typed block
|
||||
*/
|
||||
this.insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two blocks
|
||||
* @param {Block} targetBlock - previous block will be append to this block
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ export default class Caret extends Module {
|
|||
if (lastBlock.isEmpty) {
|
||||
this.setToBlock(lastBlock);
|
||||
} else {
|
||||
this.Editor.BlockManager.insert(this.config.initialBlock);
|
||||
this.Editor.BlockManager.insertAtEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue