Skip to content

Commit e875b7e

Browse files
authored
Fix issue with multiple inputs editing (#112)
1 parent e7bed44 commit e875b7e

File tree

1 file changed

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

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
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 { EventBus } from '@editorjs/sdk';
16+
import { type BlockToolAdapter as BlockToolAdapterInterface, type CoreConfig } from '@editorjs/sdk';
1317
import type { CaretAdapter } from '../CaretAdapter/index.js';
18+
import type { FormattingAdapter } from '../FormattingAdapter/index.js';
1419
import {
1520
findNextHardLineBoundary,
16-
findNextWordBoundary, findPreviousHardLineBoundary,
21+
findNextWordBoundary,
22+
findPreviousHardLineBoundary,
1723
findPreviousWordBoundary,
1824
getAbsoluteRangeOffset,
1925
getBoundaryPointByAbsoluteOffset,
2026
isNonTextInput
2127
} from '../utils/index.js';
2228
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';
2629

2730
/**
2831
* BlockToolAdapter is using inside Block tools to connect browser DOM elements to the model
@@ -547,6 +550,12 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
547550
* @param key - data key input is attached to
548551
*/
549552
#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+
550559
const isInputNative = isNativeInput(input);
551560

552561
if (isInputNative === true) {

0 commit comments

Comments
 (0)