Skip to content

Commit 1107999

Browse files
committed
Merge branch 'main' into host-before-input
2 parents e954059 + e875b7e commit 1107999

File tree

1 file changed

+21
-6
lines changed
  • packages/dom-adapters/src/BlockToolAdapter

1 file changed

+21
-6
lines changed

packages/dom-adapters/src/BlockToolAdapter/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
import { isNativeInput } from '@editorjs/dom';
22
import {
3-
type EditorJSModel,
4-
type DataKey,
3+
BlockAddedEvent,
4+
BlockRemovedEvent,
55
createDataKey,
6+
type DataKey,
7+
type EditorJSModel,
68
EventAction,
79
EventType,
810
IndexBuilder,
911
type ModelEvents,
1012
TextAddedEvent,
1113
TextRemovedEvent
1214
} from '@editorjs/model';
15+
import type {
16+
EventBus,
17+
BlockToolAdapter as BlockToolAdapterInterface,
18+
CoreConfig,
19+
BeforeInputUIEvent,
20+
BeforeInputUIEventPayload
21+
} from '@editorjs/sdk';
22+
import { BeforeInputUIEventName } from '@editorjs/sdk';
1323
import type { CaretAdapter } from '../CaretAdapter/index.js';
24+
import type { FormattingAdapter } from '../FormattingAdapter/index.js';
1425
import {
1526
findNextHardLineBoundary,
16-
findNextWordBoundary, findPreviousHardLineBoundary,
27+
findNextWordBoundary,
28+
findPreviousHardLineBoundary,
1729
findPreviousWordBoundary,
1830
getAbsoluteRangeOffset,
1931
getBoundaryPointByAbsoluteOffset,
2032
isNonTextInput
2133
} from '../utils/index.js';
2234
import { InputType } from './types/InputType.js';
23-
import { BeforeInputUIEventName, type BlockToolAdapter as BlockToolAdapterInterface, type CoreConfig } from '@editorjs/sdk';
24-
import type { FormattingAdapter } from '../FormattingAdapter/index.js';
25-
import type { BeforeInputUIEvent, BeforeInputUIEventPayload, EventBus } from '@editorjs/sdk';
2635

2736
/**
2837
* BlockToolAdapter is using inside Block tools to connect browser DOM elements to the model
@@ -578,6 +587,12 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
578587
* @param key - data key input is attached to
579588
*/
580589
#handleModelUpdate(event: ModelEvents, input: HTMLElement, key: DataKey): void {
590+
if (event instanceof BlockAddedEvent || event instanceof BlockRemovedEvent) {
591+
if (event.detail.index.blockIndex! <= this.#blockIndex) {
592+
this.#blockIndex += event.detail.action === EventAction.Added ? 1 : -1;
593+
}
594+
}
595+
581596
const isInputNative = isNativeInput(input);
582597

583598
if (isInputNative === true) {

0 commit comments

Comments
 (0)