Skip to content

Commit

Permalink
fix: #2423
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Sep 11, 2024
1 parent 84e40d3 commit 730dd8d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,7 +28,6 @@ export class DocInputController extends Disposable implements IRenderModule {

constructor(
private readonly _context: IRenderContext<DocumentDataModel>,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(DocSelectionRenderService) private readonly _docSelectionRenderService: DocSelectionRenderService,
@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,
@ICommandService private readonly _commandService: ICommandService
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {
</RadioGroup>
</div>
<div style={{ display: typeValue === 'range' ? 'block' : 'none' }}>
<RangeSelector key={`${inputId}-rangeSelector`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={rangeSelectorChange} placeholder={localeService.t('definedName.inputRangePlaceholder')} id={createInternalEditorID(`${inputId}-rangeSelector`)} width="99%" openForSheetUnitId={unitId} />
<RangeSelector key={`${inputId}-rangeSelector`} value={formulaOrRefStringValue} onValid={(value) => typeValue === 'range' && setValidFormulaOrRange(value)} onChange={rangeSelectorChange} placeholder={localeService.t('definedName.inputRangePlaceholder')} id={createInternalEditorID(`${inputId}-rangeSelector`)} width="99%" openForSheetUnitId={unitId} />
</div>
<div style={{ display: typeValue === 'range' ? 'none' : 'block' }}>
<TextEditor key={`${inputId}-editor`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={formulaEditorChange} id={createInternalEditorID(`${inputId}-editor`)} placeholder={localeService.t('definedName.inputFormulaPlaceholder')} openForSheetUnitId={unitId} onlyInputFormula={true} style={{ width: '99%' }} canvasStyle={{ fontSize: 10 }} />
<TextEditor key={`${inputId}-editor`} value={formulaOrRefStringValue} onValid={(value) => 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 }} />
</div>
<div>
<Select style={widthStyle} value={localSheetIdValue} options={options} onChange={setLocalSheetIdValue} />
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/components/editor/TextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
return;
}

const focusEditor = editorService.getFocusEditor();

if (focusEditor && focusEditor.editorUnitId !== id) {
return;
}

valueChange(editor);
});

Expand Down Expand Up @@ -258,6 +264,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
if (value == null) {
return;
}

editorService.setValueNoRefresh(value, id);
}, [value]);

Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/services/editor/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
editor.setValueLegality(false);
return false;
}

editor.setValueLegality(isReferenceStrings(value));
}

Expand Down
4 changes: 0 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 730dd8d

Please sign in to comment.