Skip to content

Commit

Permalink
fix(common): invoking onChange asap to avoid blinking on typing chine…
Browse files Browse the repository at this point in the history
…se(onComposition)
  • Loading branch information
pubuzhixing8 committed Jul 11, 2024
1 parent 332b966 commit e56c9cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-seals-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/common': patch
---

invoking onChange asap to avoid blinking on typing chinese(onComposition)
9 changes: 7 additions & 2 deletions packages/common/src/text/text-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TextManage {

textComponentRef!: TextComponentRef;

// add debounce to avoid trigger more times(from onChange and onComposition) onChange when user is typing chinese
// add debounce for composition input end and abandon before change in setTimeout period
// be going to attract board children are overwritten when fired more times onChange(eg: board is embed in editor)
textChange = debounce<TextManageChangeData>((data?: TextManageChangeData) => {
if (!data) {
Expand Down Expand Up @@ -82,10 +82,15 @@ export class TextManage {
this.editor = editor;
},
onComposition: (event: CompositionEvent) => {
if (event.type === 'compositionend') {
return;
}
const fakeRoot = buildCompositionData(this.editor, event.data);
if (fakeRoot) {
const sizeData = this.getSize(fakeRoot.children[0]);
this.textChange(sizeData);
// invoking onChange asap to avoid blinking on typing chinese
this.options.onChange && this.options.onChange({ ...sizeData });
MERGING.set(this.board, true);
}
}
};
Expand Down

0 comments on commit e56c9cb

Please sign in to comment.