Skip to content

Commit

Permalink
fix(inline): spell checker (#7294)
Browse files Browse the repository at this point in the history
This closes #6039, closes toeverything/AFFiNE#6935.
  • Loading branch information
fourdim committed Jun 13, 2024
1 parent 190ee37 commit 27c2128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/framework/inline/src/services/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class EventService<TextAttributes extends BaseTextAttributes> {
inlineEditor: this.editor,
raw: event,
inlineRange: inlineRange,
data: event.data,
data: event.data ?? event.dataTransfer?.getData('text/plain') ?? null,
attributes: {} as TextAttributes,
};
this.editor.hooks.beforeinput?.(ctx);
Expand Down
22 changes: 22 additions & 0 deletions packages/framework/inline/src/utils/transform-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ function handleInsertText<TextAttributes extends BaseTextAttributes>(
});
}

function handleInsertReplacementText<TextAttributes extends BaseTextAttributes>(
inlineRange: InlineRange,
data: string | null,
editor: InlineEditor,
attributes: TextAttributes
) {
editor.getDeltasByInlineRange(inlineRange).forEach(deltaEntry => {
attributes = { ...deltaEntry[0].attributes, ...attributes };
});
editor.deleteText(inlineRange);
if (data) {
editor.insertText(inlineRange, data, attributes);
editor.setInlineRange({
index: inlineRange.index + data.length,
length: 0,
});
}
}

function handleInsertParagraph(inlineRange: InlineRange, editor: InlineEditor) {
editor.insertLineBreak(inlineRange);
editor.setInlineRange({
Expand Down Expand Up @@ -50,6 +69,9 @@ export function transformInput<TextAttributes extends BaseTextAttributes>(
handleInsertParagraph(inlineRange, editor);
} else if (inputType.startsWith('delete')) {
handleDelete(inlineRange, editor);
} else if (inputType === 'insertReplacementText') {
// Spell Checker
handleInsertReplacementText(inlineRange, data, editor, attributes);
} else {
return;
}
Expand Down

0 comments on commit 27c2128

Please sign in to comment.