Skip to content

Commit eb7ffcb

Browse files
authored
fix(merge): after merge caret will be set in a place of glue (#2841)
* fix merge caret loosing * changelog and patch * Update nested-list * Update Backspace.cy.ts * Update Backspace.cy.ts * fix tests * fix tests
1 parent 21ac511 commit eb7ffcb

File tree

5 files changed

+38
-36
lines changed

5 files changed

+38
-36
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `New` - Inline tools (those with `isReadOnlySupported` specified) can now be used in read-only mode
66
- `Fix` - Fix selection of first block in read-only initialization with "autofocus=true"
7+
- `Fix` - Incorrect caret position after blocks merging in Safari
78

89
### 2.30.6
910

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/editorjs",
3-
"version": "2.31.0-rc.0",
3+
"version": "2.31.0-rc.1",
44
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
55
"main": "dist/editorjs.umd.js",
66
"module": "dist/editorjs.mjs",
@@ -45,7 +45,7 @@
4545
"@cypress/code-coverage": "^3.10.3",
4646
"@editorjs/code": "^2.7.0",
4747
"@editorjs/delimiter": "^1.2.0",
48-
"@editorjs/header": "^2.8.7",
48+
"@editorjs/header": "^2.8.8",
4949
"@editorjs/paragraph": "^2.11.6",
5050
"@editorjs/simple-image": "^1.4.1",
5151
"@types/node": "^18.15.11",
@@ -77,5 +77,8 @@
7777
"collective": {
7878
"type": "opencollective",
7979
"url": "https://opencollective.com/editorjs"
80+
},
81+
"dependencies": {
82+
"@editorjs/caret": "^1.0.1"
8083
}
8184
}

src/components/modules/blockEvents.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Flipper from '../flipper';
88
import type Block from '../block';
99
import { areBlocksMergeable } from '../utils/blocks';
1010
import * as caretUtils from '../utils/caret';
11+
import { focus } from '@editorjs/caret';
1112

1213
/**
1314
*
@@ -506,15 +507,17 @@ export default class BlockEvents extends Module {
506507
* @param blockToMerge - what Block we want to merge
507508
*/
508509
private mergeBlocks(targetBlock: Block, blockToMerge: Block): void {
509-
const { BlockManager, Caret, Toolbar } = this.Editor;
510+
const { BlockManager, Toolbar } = this.Editor;
510511

511-
Caret.createShadow(targetBlock.lastInput);
512+
if (targetBlock.lastInput === undefined) {
513+
return;
514+
}
515+
516+
focus(targetBlock.lastInput, false);
512517

513518
BlockManager
514519
.mergeBlocks(targetBlock, blockToMerge)
515520
.then(() => {
516-
/** Restore caret position after merge */
517-
Caret.restoreCaret(targetBlock.pluginsContent as HTMLElement);
518521
Toolbar.close();
519522
});
520523
}

test/cypress/fixtures/tools/SimpleHeader.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
*/
1111
export class SimpleHeader implements BaseTool {
1212
private _data: BlockToolData;
13-
private element: HTMLHeadingElement;
13+
private element: HTMLHeadingElement | null = null;
1414

1515
/**
1616
*
@@ -39,10 +39,7 @@ export class SimpleHeader implements BaseTool {
3939
* @param data - saved data to merger with current block
4040
*/
4141
public merge(data: BlockToolData): void {
42-
this.data = {
43-
text: this.data.text + data.text,
44-
level: this.data.level,
45-
};
42+
this.element?.insertAdjacentHTML('beforeend', data.text);
4643
}
4744

4845
/**
@@ -66,25 +63,4 @@ export class SimpleHeader implements BaseTool {
6663
import: 'text', // fill 'text' property from other block's export string
6764
};
6865
}
69-
70-
/**
71-
* Data getter
72-
*/
73-
private get data(): BlockToolData {
74-
this._data.text = this.element.innerHTML;
75-
this._data.level = 1;
76-
77-
return this._data;
78-
}
79-
80-
/**
81-
* Data setter
82-
*/
83-
private set data(data: BlockToolData) {
84-
this._data = data;
85-
86-
if (data.text !== undefined) {
87-
this.element.innerHTML = this._data.text || '';
88-
}
89-
}
9066
}

yarn.lock

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,13 @@
550550
debug "^3.1.0"
551551
lodash.once "^4.1.1"
552552

553+
"@editorjs/caret@^1.0.1":
554+
version "1.0.1"
555+
resolved "https://registry.yarnpkg.com/@editorjs/caret/-/caret-1.0.1.tgz#0d33ca67a2d29d09fdea10d3d30b660f0abc7cfd"
556+
integrity sha512-yMewrc/dndBbgmluFory0GbVWXnD9rhcE/xgwM0ecHWQodyfY3ZIJLvSQhf+BbgncitMlUG/FYqjJCL2Axi4+g==
557+
dependencies:
558+
"@editorjs/dom" "^1.0.0"
559+
553560
"@editorjs/code@^2.7.0":
554561
version "2.8.0"
555562
resolved "https://registry.yarnpkg.com/@editorjs/code/-/code-2.8.0.tgz#d31fdd947b9c763daae2cd2eabdf8dc37c0c6f5a"
@@ -564,19 +571,31 @@
564571
dependencies:
565572
"@codexteam/icons" "^0.0.5"
566573

574+
"@editorjs/dom@^1.0.0":
575+
version "1.0.0"
576+
resolved "https://registry.yarnpkg.com/@editorjs/dom/-/dom-1.0.0.tgz#ddf7f17651a091570766c5fa44c89ecf8a183c82"
577+
integrity sha512-P5qZaQaG8NQXm2XuEDlcfDm8S1Kvdegwf0E/ld2RnwZquY5l27hufaW57w0SikT75mscr+dARQ68Gx/xEQEUKw==
578+
dependencies:
579+
"@editorjs/helpers" "^1.0.0"
580+
567581
"@editorjs/editorjs@^2.29.1":
568582
version "2.30.2"
569583
resolved "https://registry.yarnpkg.com/@editorjs/editorjs/-/editorjs-2.30.2.tgz#b045af18a9ebe0c02cb32be41b2a98e23ee08e59"
570584
integrity sha512-JjtUDs2/aHTEjNZzEf/2cugpIli1+aNeU8mloOd5USbVxv2vC02HTMpv7Vc1UyB7dIuc45JaYSJwgnBZp9duhA==
571585

572-
"@editorjs/header@^2.8.7":
573-
version "2.8.7"
574-
resolved "https://registry.yarnpkg.com/@editorjs/header/-/header-2.8.7.tgz#6aa34e01638d18fbbc6d3bd75f1844869eca9193"
575-
integrity sha512-rfxzYFR/Jhaocj3Xxx8XjEjyzfPbBIVkcPZ9Uy3rEz1n3ewhV0V4zwuxCjVfFhLUVgQQExq43BxJnTNlLOzqDQ==
586+
"@editorjs/header@^2.8.8":
587+
version "2.8.8"
588+
resolved "https://registry.yarnpkg.com/@editorjs/header/-/header-2.8.8.tgz#43cff7949c44866da7716fdb562d68116d0a806a"
589+
integrity sha512-bsMSs34u2hoi0UBuRoc5EGWXIFzJiwYgkFUYQGVm63y5FU+s8zPBmVx5Ip2sw1xgs0fqfDROqmteMvvmbCy62w==
576590
dependencies:
577591
"@codexteam/icons" "^0.0.5"
578592
"@editorjs/editorjs" "^2.29.1"
579593

594+
"@editorjs/helpers@^1.0.0":
595+
version "1.0.0"
596+
resolved "https://registry.yarnpkg.com/@editorjs/helpers/-/helpers-1.0.0.tgz#4b0e0868e51e2772a73212f4aac5aff553725894"
597+
integrity sha512-ih4yCm+x+7X9XCn1zxfNous2LQX8ZYMyTHMLdgbyjBf0Opf8GdLxVjdzSjkA+0mUp1tUe3JgWW3FTisYcSnbQA==
598+
580599
"@editorjs/paragraph@^2.11.6":
581600
version "2.11.6"
582601
resolved "https://registry.yarnpkg.com/@editorjs/paragraph/-/paragraph-2.11.6.tgz#011444187a74dc603201dce37d2fc6d054022407"

0 commit comments

Comments
 (0)