mirror of
https://github.com/codex-team/editor.js
synced 2024-06-08 00:42:31 +02:00
Fix BlockManager.setCurrentBlockByChildNode() with multiple Editor.js instances
This commit is contained in:
parent
c0ff646e8e
commit
7c8778acc4
2
dist/editor.js
vendored
2
dist/editor.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,7 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
- `Fix` - Fix BlockManager.setCurrentBlockByChildNode() with multiple Editor.js instances [#1503](https://github.com/codex-team/editor.js/issues/1503).
|
||||||
|
|
||||||
### 2.19.1
|
### 2.19.1
|
||||||
|
|
||||||
- `Improvements` - The [Cypress](https://www.cypress.io) was integrated as the end-to-end testing framework
|
- `Improvements` - The [Cypress](https://www.cypress.io) was integrated as the end-to-end testing framework
|
||||||
|
|
|
@ -560,10 +560,8 @@ export default class BlockManager extends Module {
|
||||||
* 2) Mark it as current
|
* 2) Mark it as current
|
||||||
*
|
*
|
||||||
* @param {Node} childNode - look ahead from this node.
|
* @param {Node} childNode - look ahead from this node.
|
||||||
*
|
|
||||||
* @throws Error - when passed Node is not included at the Block
|
|
||||||
*/
|
*/
|
||||||
public setCurrentBlockByChildNode(childNode: Node): Block {
|
public setCurrentBlockByChildNode(childNode: Node): Block | undefined {
|
||||||
/**
|
/**
|
||||||
* If node is Text TextNode
|
* If node is Text TextNode
|
||||||
*/
|
*/
|
||||||
|
@ -573,23 +571,23 @@ export default class BlockManager extends Module {
|
||||||
|
|
||||||
const parentFirstLevelBlock = (childNode as HTMLElement).closest(`.${Block.CSS.wrapper}`);
|
const parentFirstLevelBlock = (childNode as HTMLElement).closest(`.${Block.CSS.wrapper}`);
|
||||||
|
|
||||||
if (parentFirstLevelBlock) {
|
if (!parentFirstLevelBlock?.closest(`.${this.Editor.UI.CSS.editorWrapper}`)?.isEqualNode(this.Editor.UI.nodes.wrapper)) {
|
||||||
/**
|
return;
|
||||||
* Update current Block's index
|
|
||||||
*
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
this.currentBlockIndex = this._blocks.nodes.indexOf(parentFirstLevelBlock as HTMLElement);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update current block active input
|
|
||||||
*/
|
|
||||||
this.currentBlock.updateCurrentInput();
|
|
||||||
|
|
||||||
return this.currentBlock;
|
|
||||||
} else {
|
|
||||||
throw new Error('Can not find a Block from this child Node');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update current Block's index
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.currentBlockIndex = this._blocks.nodes.indexOf(parentFirstLevelBlock as HTMLElement);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update current block active input
|
||||||
|
*/
|
||||||
|
this.currentBlock.updateCurrentInput();
|
||||||
|
|
||||||
|
return this.currentBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -87,16 +87,16 @@ export default class DragNDrop extends Module {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to set current block by drop target.
|
* Try to set current block by drop target.
|
||||||
* If drop target (error will be thrown) is not part of the Block, set last Block as current.
|
* If drop target is not part of the Block, set last Block as current.
|
||||||
*/
|
*/
|
||||||
try {
|
const targetBlock = BlockManager.setCurrentBlockByChildNode(dropEvent.target as Node);
|
||||||
const targetBlock = BlockManager.setCurrentBlockByChildNode(dropEvent.target as Node);
|
|
||||||
|
|
||||||
|
if (targetBlock) {
|
||||||
this.Editor.Caret.setToBlock(targetBlock, Caret.positions.END);
|
this.Editor.Caret.setToBlock(targetBlock, Caret.positions.END);
|
||||||
} catch (e) {
|
} else {
|
||||||
const targetBlock = BlockManager.setCurrentBlockByChildNode(BlockManager.lastBlock.holder);
|
const lastBlock = BlockManager.setCurrentBlockByChildNode(BlockManager.lastBlock.holder);
|
||||||
|
|
||||||
this.Editor.Caret.setToBlock(targetBlock, Caret.positions.END);
|
this.Editor.Caret.setToBlock(lastBlock, Caret.positions.END);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Paste.processDataTransfer(dropEvent.dataTransfer, true);
|
await Paste.processDataTransfer(dropEvent.dataTransfer, true);
|
||||||
|
|
Loading…
Reference in a new issue