Skip to content

Commit

Permalink
Set caret when block data pasted
Browse files Browse the repository at this point in the history
  • Loading branch information
hata6502 committed Dec 10, 2020
1 parent 36d5a67 commit 75d1d32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

- `Improvements` - Set caret when block data pasted [#1470](https://github.com/codex-team/editor.js/pull/1470)

### 2.19.1

- `Improvements` - The [Cypress](https://www.cypress.io) was integrated as the end-to-end testing framework
- `Improvements` - Native `typeof`replaced with custom utils methods
- `Improvements` - Bind shortcuts listeners on the editor wrapper instead of document (#1391)(https://github.com/codex-team/editor.js/issues/1391)
- `Improvements` - Bind shortcuts listeners on the editor wrapper instead of document [#1391](https://github.com/codex-team/editor.js/issues/1391)
- `Fix` - The problem with destroy() method [#1380](https://github.com/codex-team/editor.js/issues/1380).
- `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)
Expand Down
6 changes: 4 additions & 2 deletions src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export default class Paste extends Module {
* @returns {void}
*/
private insertEditorJSData(blocks: Array<Pick<SavedData, 'data' | 'tool'>>): void {
const { BlockManager, Sanitizer, Tools } = this.Editor;
const { BlockManager, Caret, Sanitizer, Tools } = this.Editor;
const sanitizedBlocks = Sanitizer.sanitizeBlocks(blocks);

sanitizedBlocks.forEach(({ tool, data }, i) => {
Expand All @@ -772,11 +772,13 @@ export default class Paste extends Module {
needToReplaceCurrentBlock = isCurrentBlockDefault && BlockManager.currentBlock.isEmpty;
}

BlockManager.insert({
const block = BlockManager.insert({
tool,
data,
replace: needToReplaceCurrentBlock,
});

Caret.setToBlock(block, Caret.positions.END);
});
}

Expand Down

0 comments on commit 75d1d32

Please sign in to comment.