Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(docs): add more event to input observable (#3582)

Ran Luo2fc56ff62a5e
diff --git a/packages/docs-ui/src/services/editor/editor.ts b/packages/docs-ui/src/services/editor/editor.ts
index 607fc41493..98f3f412e9 100644
--- a/packages/docs-ui/src/services/editor/editor.ts
+++ b/packages/docs-ui/src/services/editor/editor.ts
@@ -15,7 +15,7 @@
*/
import { DEFAULT_STYLES, Disposable, UniverInstanceType } from '@univerjs/core';
-import { type Observable, Subject } from 'rxjs';
+import { merge, type Observable, Subject } from 'rxjs';
import type { DocumentDataModel, ICommandService, IDocumentData, IDocumentStyle, IPosition, IUndoRedoService, IUniverInstanceService, Nullable } from '@univerjs/core';
import type { DocSelectionManagerService } from '@univerjs/docs';
import type { IDocSelectionInnerParam, IRender, ISuccinctDocRangeParam, ITextRangeWithStyle } from '@univerjs/engine-render';
@@ -213,17 +213,28 @@ export class Editor extends Disposable implements IEditor {
);
this.disposeWithMe(
- docSelectionRenderService.onInput$.subscribe((e) => {
- const { content = '' } = e;
- const data = this.getDocumentData();
-
- this._input$.next({
- target: this,
- content,
- data,
- isComposing: false,
- });
- })
+ merge(
+ docSelectionRenderService.onInput$,
+ docSelectionRenderService.onKeydown$,
+ docSelectionRenderService.onCompositionupdate$,
+ docSelectionRenderService.onCompositionend$,
+ docSelectionRenderService.onPaste$
+ )
+ .subscribe((e) => {
+ if (e == null) {
+ return;
+ }
+
+ const { content = '' } = e;
+ const data = this.getDocumentData();
+
+ this._input$.next({
+ target: this,
+ content,
+ data,
+ isComposing: e.event.type === 'compositionupdate',
+ });
+ })
);
this.disposeWithMe(
diff --git a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
index 4d5917a6d8..e848df4ca3 100644
--- a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
+++ b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
@@ -37,7 +37,7 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
private readonly _onInputBefore$ = new Subject<Nullable<IEditorInputConfig>>();
readonly onInputBefore$ = this._onInputBefore$.asObservable();
- private readonly _onKeydown$ = new BehaviorSubject<Nullable<IEditorInputConfig>>(null);
+ private readonly _onKeydown$ = new Subject<IEditorInputConfig>();
readonly onKeydown$ = this._onKeydown$.asObservable();
private readonly _onInput$ = new Subject<IEditorInputConfig>();