Skip to content

Commit

Permalink
unhardcode paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
neSpecc committed Aug 31, 2024
1 parent 40d0c73 commit 52fa52f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion packages/core/src/components/BlockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ export class BlocksManager {
throw new Error('[BlockManager] Block index should be defined. Probably something wrong with the Editor Model. Please, report this issue');
}

const blockToolAdapter = new BlockToolAdapter(this.#model, this.#caretAdapter, index.blockIndex, this.#formattingAdapter);
const toolName = event.detail.data.name;

const blockToolAdapter = new BlockToolAdapter(
this.#model,
this.#caretAdapter,
index.blockIndex,
this.#formattingAdapter,
toolName
);

const tool = this.#toolsManager.blockTools.get(data.name);

Expand Down
18 changes: 15 additions & 3 deletions packages/dom-adapters/src/BlockToolAdapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,26 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
*/
#formattingAdapter: FormattingAdapter;

/**
* Name of the tool that this adapter is connected to
*/
#toolName: string;

/**
* BlockToolAdapter constructor
*
* @param model - EditorJSModel instance
* @param caretAdapter - CaretAdapter instance
* @param blockIndex - index of the block that this adapter is connected to
* @param formattingAdapter - needed to render formatted text
* @param toolName - tool name of the block
*/
constructor(model: EditorJSModel, caretAdapter: CaretAdapter, blockIndex: number, formattingAdapter: FormattingAdapter) {
constructor(model: EditorJSModel, caretAdapter: CaretAdapter, blockIndex: number, formattingAdapter: FormattingAdapter, toolName: string) {
this.#model = model;
this.#blockIndex = blockIndex;
this.#caretAdapter = caretAdapter;
this.#formattingAdapter = formattingAdapter;
this.#toolName = toolName;
}

/**
Expand Down Expand Up @@ -311,14 +318,15 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {

case InputType.InsertParagraph:
this.#handleSplit(key, start, end);

break;
case InputType.InsertLineBreak:
/**
* @todo Think if we need to keep that or not
*/
if (isInputNative === true) {
this.#model.insertText(this.#blockIndex, key, '\n', start);
}
break;
default:
}
};
Expand All @@ -338,7 +346,7 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {

this.#model.removeText(this.#blockIndex, key, start, currentValue.length);
this.#model.addBlock({
name: 'paragraph',
name: this.#toolName,
data : {
[key]: {
$t: 't',
Expand All @@ -347,6 +355,10 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
}

Check warning on line 355 in packages/dom-adapters/src/BlockToolAdapter/index.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
}

Check warning on line 356 in packages/dom-adapters/src/BlockToolAdapter/index.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
}, this.#blockIndex + 1);

/**
* Raf is needed to ensure that the new block is added so caret can be moved to it
*/
requestAnimationFrame(() => {

Check warning on line 362 in packages/dom-adapters/src/BlockToolAdapter/index.ts

View workflow job for this annotation

GitHub Actions / lint

'requestAnimationFrame' is not defined
this.#caretAdapter.updateIndex(
new IndexBuilder()
Expand Down

0 comments on commit 52fa52f

Please sign in to comment.