|
1 | 1 | import { isNativeInput } from '@editorjs/dom'; |
2 | 2 | import { |
3 | | - type EditorJSModel, |
4 | | - type DataKey, |
| 3 | + BlockAddedEvent, |
| 4 | + BlockRemovedEvent, |
5 | 5 | createDataKey, |
| 6 | + type DataKey, |
| 7 | + type EditorJSModel, |
6 | 8 | EventAction, |
7 | 9 | EventType, |
8 | 10 | IndexBuilder, |
9 | 11 | type ModelEvents, |
10 | 12 | TextAddedEvent, |
11 | 13 | TextRemovedEvent |
12 | 14 | } from '@editorjs/model'; |
| 15 | +import type { EventBus } from '@editorjs/sdk'; |
| 16 | +import { type BlockToolAdapter as BlockToolAdapterInterface, type CoreConfig } from '@editorjs/sdk'; |
13 | 17 | import type { CaretAdapter } from '../CaretAdapter/index.js'; |
| 18 | +import type { FormattingAdapter } from '../FormattingAdapter/index.js'; |
14 | 19 | import { |
15 | 20 | findNextHardLineBoundary, |
16 | | - findNextWordBoundary, findPreviousHardLineBoundary, |
| 21 | + findNextWordBoundary, |
| 22 | + findPreviousHardLineBoundary, |
17 | 23 | findPreviousWordBoundary, |
18 | 24 | getAbsoluteRangeOffset, |
19 | 25 | getBoundaryPointByAbsoluteOffset, |
20 | 26 | isNonTextInput |
21 | 27 | } from '../utils/index.js'; |
22 | 28 | import { InputType } from './types/InputType.js'; |
23 | | -import { type BlockToolAdapter as BlockToolAdapterInterface, type CoreConfig } from '@editorjs/sdk'; |
24 | | -import type { FormattingAdapter } from '../FormattingAdapter/index.js'; |
25 | | -import type { EventBus } from '@editorjs/sdk'; |
26 | 29 |
|
27 | 30 | /** |
28 | 31 | * BlockToolAdapter is using inside Block tools to connect browser DOM elements to the model |
@@ -547,6 +550,12 @@ export class BlockToolAdapter implements BlockToolAdapterInterface { |
547 | 550 | * @param key - data key input is attached to |
548 | 551 | */ |
549 | 552 | #handleModelUpdate(event: ModelEvents, input: HTMLElement, key: DataKey): void { |
| 553 | + if (event instanceof BlockAddedEvent || event instanceof BlockRemovedEvent) { |
| 554 | + if (event.detail.index.blockIndex! <= this.#blockIndex) { |
| 555 | + this.#blockIndex += event.detail.action === EventAction.Added ? 1 : -1; |
| 556 | + } |
| 557 | + } |
| 558 | + |
550 | 559 | const isInputNative = isNativeInput(input); |
551 | 560 |
|
552 | 561 | if (isInputNative === true) { |
|
0 commit comments