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.

fix(uni): add set-editor-resize-operation (#4043)

Gpound.liu8b6ef1dc18f4
diff --git a/packages-experimental/uniui/src/plugin.ts b/packages-experimental/uniui/src/plugin.ts
index ea1827d308..441aca30cd 100644
--- a/packages-experimental/uniui/src/plugin.ts
+++ b/packages-experimental/uniui/src/plugin.ts
@@ -16,7 +16,7 @@
import type { Dependency } from '@univerjs/core';
import type { IUniverUIConfig } from '@univerjs/ui';
-import { DependentOn, IContextService, ILocalStorageService, Inject, Injector, mergeOverrideWithDependencies, Plugin, Tools } from '@univerjs/core';
+import { DependentOn, ICommandService, IContextService, ILocalStorageService, Inject, Injector, mergeOverrideWithDependencies, Plugin, Tools } from '@univerjs/core';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import {
BrowserClipboardService,
@@ -85,7 +85,8 @@ export class UniverUniUIPlugin extends Plugin {
constructor(
private readonly _config: Partial<IUniverUIConfig> = {},
@Inject(Injector) protected readonly _injector: Injector,
- @IContextService private readonly _contextService: IContextService
+ @IContextService private readonly _contextService: IContextService,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
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 a4d8584162..f6aad17626 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
@@ -20,7 +20,6 @@ import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { checkForSubstrings, Disposable, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { IRenderManagerService, ScrollBar } from '@univerjs/engine-render';
-import { SetEditorResizeOperation } from '@univerjs/ui';
import { fromEvent } from 'rxjs';
import { VIEWPORT_KEY } from '../../basics/docs-view-key';
import { CoverContentCommand } from '../../commands/commands/replace-content.command';
@@ -289,7 +288,7 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu
* Listen to document edits to refresh the size of the formula editor.
*/
private _commandExecutedListener() {
- const updateCommandList = [RichTextEditingMutation.id, SetEditorResizeOperation.id];
+ const updateCommandList = [RichTextEditingMutation.id];
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
diff --git a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
index da6f3aa1ef..a5a3df46c1 100644
--- a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
@@ -33,7 +33,8 @@ import type {
} from '@univerjs/sheets';
import type { EditorBridgeService, SelectionControl } from '@univerjs/sheets-ui';
import type { ISelectEditorFormulaOperationParam } from '../commands/operations/editor-formula.operation';
-import { AbsoluteRefType,
+import {
+ AbsoluteRefType,
Direction,
Disposable,
DisposableCollection,
@@ -94,9 +95,10 @@ import {
isRangeSelector,
JumpOver,
MoveSelectionCommand,
+ SheetCellEditorResizeService,
SheetSkeletonManagerService,
} from '@univerjs/sheets-ui';
-import { IContextMenuService, ILayoutService, KeyCode, MetaKeys, SetEditorResizeOperation, UNI_DISABLE_CHANGING_FOCUS_KEY } from '@univerjs/ui';
+import { IContextMenuService, ILayoutService, KeyCode, MetaKeys, UNI_DISABLE_CHANGING_FOCUS_KEY } from '@univerjs/ui';
import { distinctUntilChanged, distinctUntilKeyChanged, filter, merge } from 'rxjs';
import { SelectEditorFormulaOperation } from '../commands/operations/editor-formula.operation';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
@@ -191,6 +193,7 @@ export class PromptController extends Disposable {
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@IEditorService private readonly _editorService: IEditorService,
@ILayoutService private readonly _layoutService: ILayoutService
+
) {
super();
@@ -1337,13 +1340,25 @@ export class PromptController extends Disposable {
private _fitEditorSize() {
const currentDocumentDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
const editorUnitId = currentDocumentDataModel!.getUnitId();
+
if (this._editorService.isEditor(editorUnitId) && !this._editorService.isSheetEditor(editorUnitId)) {
return;
}
+ this._editorBridgeService.changeEditorDirty(true);
+ if (!this._editorBridgeService.isVisible().visible) {
+ return;
+ }
- this._commandService.executeCommand(SetEditorResizeOperation.id, {
- unitId: editorUnitId,
- });
+ if (editorUnitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
+ const workbookUnitId = workbook?.getUnitId() ?? '';
+ const render = this._renderManagerService.getRenderById(workbookUnitId);
+ if (!render) {
+ return;
+ }
+ const sheetCellEditorResizeService = render.with(SheetCellEditorResizeService);
+ sheetCellEditorResizeService.fitTextSize();
+ }
}
/**
diff --git a/packages/sheets-ui/src/controllers/editor/data-sync.controller.ts b/packages/sheets-ui/src/controllers/editor/data-sync.controller.ts
index 546b52f007..11fda5f36a 100644
--- a/packages/sheets-ui/src/controllers/editor/data-sync.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/data-sync.controller.ts
@@ -23,7 +23,6 @@ import { BooleanNumber, Disposable, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NO
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import { MoveRangeMutation, RangeProtectionRuleModel, SetRangeValuesMutation, WorksheetProtectionRuleModel } from '@univerjs/sheets';
-import { SetEditorResizeOperation } from '@univerjs/ui';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { FormulaEditorController } from './formula-editor.controller';
@@ -100,7 +99,7 @@ export class EditorDataSyncController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (command.id === RichTextEditingMutation.id || command.id === SetEditorResizeOperation.id) {
+ if (command.id === RichTextEditingMutation.id) {
const params = command.params as IRichTextEditingMutationParams;
const { unitId } = params;
if (params.isSync) {
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index f9369ad4ef..f730b63753 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -57,7 +57,7 @@ import {
} from '@univerjs/engine-render';
import { COMMAND_LISTENER_SKELETON_CHANGE, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
-import { KeyCode, SetEditorResizeOperation } from '@univerjs/ui';
+import { KeyCode } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import { getEditorObject } from '../../basics/editor/get-editor-object';
import { MoveSelectionCommand, MoveSelectionEnterAndTabCommand } from '../../commands/commands/set-selection.command';
@@ -293,7 +293,7 @@ export class EditingRenderController extends Disposable implements IRenderModule
* Listen to document edits to refresh the size of the sheet editor, not for normal editor.
*/
private _commandExecutedListener(d: DisposableCollection) {
- const updateCommandList = [RichTextEditingMutation.id, SetEditorResizeOperation.id];
+ const updateCommandList = [RichTextEditingMutation.id];
d.add(this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index ac32e0a830..09c1de87e3 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -111,7 +111,7 @@ export { FONT_SIZE_COMPONENT } from './components/font-size/interface';
export { SELECTION_SHAPE_DEPTH } from './services/selection/const';
export { isRangeSelector, RANGE_SELECTOR_SYMBOLS } from './controllers/editor/utils/isRangeSelector';
export { EMBEDDING_FORMULA_EDITOR, isEmbeddingFormulaEditor } from './controllers/editor/utils/isEmbeddingFormulaEditor';
-
+export { SheetCellEditorResizeService } from './services/editor/cell-editor-resize.service';
export { menuSchema } from './controllers/menu.schema';
export { getCellRealRange } from './common/utils';
diff --git a/packages/ui/src/commands/operations/editor/set-editor-resize.operation.ts b/packages/ui/src/commands/operations/editor/set-editor-resize.operation.ts
deleted file mode 100644
index cdcde76661..0000000000
--- a/packages/ui/src/commands/operations/editor/set-editor-resize.operation.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { IOperation } from '@univerjs/core';
-import { CommandType } from '@univerjs/core';
-
-export const SetEditorResizeOperation: IOperation = {
- id: 'sheet.operation.set-editor-resize',
- type: CommandType.OPERATION,
- handler: (accessor, params) => true,
-};
diff --git a/packages/ui/src/controllers/shared-shortcut.controller.ts b/packages/ui/src/controllers/shared-shortcut.controller.ts
index 043f8041f4..fe4b737794 100644
--- a/packages/ui/src/controllers/shared-shortcut.controller.ts
+++ b/packages/ui/src/controllers/shared-shortcut.controller.ts
@@ -18,7 +18,6 @@ import type { IContextService } from '@univerjs/core';
import type { IShortcutItem } from '../services/shortcut/shortcut.service';
import { Disposable, FOCUSING_UNIVER_EDITOR, ICommandService, RedoCommand, UndoCommand } from '@univerjs/core';
-import { SetEditorResizeOperation } from '../commands/operations/editor/set-editor-resize.operation';
import { CopyCommand, CutCommand, PasteCommand } from '../services/clipboard/clipboard.command';
import { KeyCode, MetaKeys } from '../services/shortcut/keycode';
import { IShortcutService } from '../services/shortcut/shortcut.service';
@@ -103,7 +102,7 @@ export class SharedController extends Disposable {
}
private _registerCommands(): void {
- [CutCommand, CopyCommand, PasteCommand, SetEditorResizeOperation].forEach((command) =>
+ [CutCommand, CopyCommand, PasteCommand].forEach((command) =>
this.disposeWithMe(this._commandService.registerMultipleCommand(command))
);
}
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 80e56361fa..99743a4d5f 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -134,7 +134,6 @@ export { Sidebar } from './views/components/sidebar/Sidebar';
// #region - all commands
-export { SetEditorResizeOperation } from './commands/operations/editor/set-editor-resize.operation';
export { ToggleShortcutPanelOperation } from './commands/operations/toggle-shortcut-panel.operation';
// #endregion