From 730dd8d0df5c2c1dadc50f2d303f6f820c7f4d88 Mon Sep 17 00:00:00 2001 From: jocs Date: Tue, 10 Sep 2024 20:08:36 +0800 Subject: [PATCH] fix: #2423 --- .../render-controllers/doc-editor-bridge.controller.ts | 8 ++++++++ .../render-controllers/doc-input.controller.ts | 10 ++-------- .../src/views/defined-name/DefinedNameInput.tsx | 4 ++-- packages/ui/src/components/editor/TextEditor.tsx | 7 +++++++ packages/ui/src/services/editor/editor.service.ts | 1 + pnpm-lock.yaml | 4 ---- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts index d6fe0de8166..0dfa2d45dfa 100644 --- a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts +++ b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts @@ -159,6 +159,10 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu private _initialSetValue() { this.disposeWithMe( this._editorService.setValue$.subscribe((param) => { + if (param.editorUnitId !== this._context.unitId) { + return; + } + this._commandService.executeCommand(CoverContentCommand.id, { unitId: param.editorUnitId, body: param.body, @@ -197,6 +201,10 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu private _initialFocus() { this.disposeWithMe( this._editorService.focus$.subscribe((textRange) => { + if (this._editorService.getFocusEditor()?.editorUnitId !== this._context.unitId) { + return; + } + this._docSelectionRenderService.removeAllRanges(); this._docSelectionRenderService.addDocRanges([textRange]); }) diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts index aa403675f3f..e93967d4c50 100644 --- a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts +++ b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts @@ -15,7 +15,7 @@ */ import type { DocumentDataModel, Nullable } from '@univerjs/core'; -import { Disposable, ICommandService, Inject, IUniverInstanceService } from '@univerjs/core'; +import { Disposable, ICommandService, Inject } from '@univerjs/core'; import type { IRenderContext, IRenderModule } from '@univerjs/engine-render'; import type { Subscription } from 'rxjs'; import { DocSkeletonManagerService } from '@univerjs/docs'; @@ -28,7 +28,6 @@ export class DocInputController extends Disposable implements IRenderModule { constructor( private readonly _context: IRenderContext, - @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService, @Inject(DocSelectionRenderService) private readonly _docSelectionRenderService: DocSelectionRenderService, @Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService, @ICommandService private readonly _commandService: ICommandService @@ -54,12 +53,7 @@ export class DocInputController extends Disposable implements IRenderModule { return; } - const documentModel = this._univerInstanceService.getCurrentUniverDocInstance(); - if (!documentModel) { - return; - } - - const unitId = documentModel.getUnitId(); + const unitId = this._context.unitId; const { event, content = '', activeRange } = config; diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx index 80e78daf45c..5e14f5592b3 100644 --- a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx +++ b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx @@ -210,10 +210,10 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {
- + typeValue === 'range' && setValidFormulaOrRange(value)} onChange={rangeSelectorChange} placeholder={localeService.t('definedName.inputRangePlaceholder')} id={createInternalEditorID(`${inputId}-rangeSelector`)} width="99%" openForSheetUnitId={unitId} />
- + typeValue !== 'range' && setValidFormulaOrRange(value)} onChange={formulaEditorChange} id={createInternalEditorID(`${inputId}-editor`)} placeholder={localeService.t('definedName.inputFormulaPlaceholder')} openForSheetUnitId={unitId} onlyInputFormula={true} style={{ width: '99%' }} canvasStyle={{ fontSize: 10 }} />