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(sheets-ui): set focus editing mode when dbclick & error resize when change sub sheet (#3725)

zhangw84ac33f9a58e
diff --git a/packages/sheets-data-validation-ui/src/views/detail/index.tsx b/packages/sheets-data-validation-ui/src/views/detail/index.tsx
index 9ba1f5c862..094cebec99 100644
--- a/packages/sheets-data-validation-ui/src/views/detail/index.tsx
+++ b/packages/sheets-data-validation-ui/src/views/detail/index.tsx
@@ -21,6 +21,7 @@ import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryS
import { Button, FormLayout, Select } from '@univerjs/design';
import { RangeSelector } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
+import { SheetsSelectionsService } from '@univerjs/sheets';
import { RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '@univerjs/sheets-data-validation';
import { ComponentManager, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
@@ -56,6 +57,16 @@ export function DataValidationDetail() {
const validators = validatorService.getValidatorsByScope(DataValidatorRegistryScope.SHEET);
const [localRanges, setLocalRanges] = useState<IUnitRange[]>(() => localRule.ranges.map((i) => ({ unitId: '', sheetId: '', range: i })));
const debounceExecute = useMemo(() => debounceExecuteFactory(commandService), [commandService]);
+ const sheetSelectionService = useDependency(SheetsSelectionsService);
+
+ useEffect(() => {
+ return () => {
+ const currentSelection = sheetSelectionService.getCurrentSelections();
+ if (currentSelection) {
+ sheetSelectionService.setSelections([...currentSelection]);
+ }
+ };
+ }, [sheetSelectionService]);
useEffect(() => {
commandService.onCommandExecuted((commandInfo) => {
diff --git a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
index bbae714eb0..4b6dbdde59 100644
--- a/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula-ui/src/controllers/prompt.controller.ts
@@ -252,46 +252,55 @@ export class PromptController extends Disposable {
private _initialCursorSync() {
this.disposeWithMe(
- this._docSelectionManagerService.textSelection$.subscribe((params) => {
- if (params?.unitId == null) {
- return;
- }
+ this._docSelectionManagerService.textSelection$
+ .pipe(
+ distinctUntilChanged(
+ (prev, curr) =>
+ prev?.unitId === curr?.unitId &&
+ prev?.segmentId === curr?.segmentId &&
+ Boolean(prev?.textRanges.every((t, i) => t.startOffset === curr?.textRanges[i].startOffset && t.endOffset === curr?.textRanges[i].endOffset))
+ )
+ )
+ .subscribe((params) => {
+ if (params?.unitId == null) {
+ return;
+ }
- const editor = this._editorService.getEditor(params.unitId);
- if (!editor
+ const editor = this._editorService.getEditor(params.unitId);
+ if (!editor
|| editor.onlyInputContent()
|| (editor.isSheetEditor() && !this._isFormulaEditorActivated())
// Remove this latter.
|| editor.params.scrollBar
- ) {
- return;
- }
+ ) {
+ return;
+ }
- const onlyInputRange = editor.onlyInputRange();
+ const onlyInputRange = editor.onlyInputRange();
// @ts-ignore
- if (params?.options?.fromSelection) {
- return;
- } else {
- this._quitSelectingMode();
- }
+ if (params?.options?.fromSelection) {
+ return;
+ } else {
+ this._quitSelectingMode();
+ }
- this._contextSwitch();
- this._checkShouldEnterSelectingMode(onlyInputRange);
+ this._contextSwitch();
+ this._checkShouldEnterSelectingMode(onlyInputRange);
- if (this._formulaPromptService.isLockedSelectionChange()) {
- return;
- }
+ if (this._formulaPromptService.isLockedSelectionChange()) {
+ return;
+ }
- this._highlightFormula();
+ this._highlightFormula();
- if (onlyInputRange) {
- return;
- }
+ if (onlyInputRange) {
+ return;
+ }
// TODO@Dushusir: use real text info
- this._changeFunctionPanelState();
- })
+ this._changeFunctionPanelState();
+ })
);
}
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 da8486be62..de27ed7513 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -62,7 +62,7 @@ import {
ScrollBar,
} from '@univerjs/engine-render';
-import { ClearSelectionFormatCommand, COMMAND_LISTENER_SKELETON_CHANGE, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetActivateCommand, SheetsSelectionsService } from '@univerjs/sheets';
+import { ClearSelectionFormatCommand, COMMAND_LISTENER_SKELETON_CHANGE, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
import { ILayoutService, KeyCode, SetEditorResizeOperation } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import { getEditorObject } from '../../basics/editor/get-editor-object';
@@ -245,6 +245,8 @@ export class EditingRenderController extends Disposable implements IRenderModule
private _initSkeletonListener(d: DisposableCollection) {
const commandList = new Set(COMMAND_LISTENER_SKELETON_CHANGE);
+ commandList.delete(SetWorksheetActiveOperation.id);
+
d.add(this._commandService.onCommandExecuted((commandInfo) => {
if (!commandList.has(commandInfo.id)) {
return;
@@ -259,12 +261,12 @@ export class EditingRenderController extends Disposable implements IRenderModule
if (!state) return;
if (!this._editorBridgeService.isVisible().visible) return;
this._editorBridgeService.refreshEditCellPosition(true);
- const latestEditCellState = this._editorBridgeService.getEditCellState();
- if (!latestEditCellState) return;
+ const editCellState = this._editorBridgeService.getEditCellState();
+ if (!editCellState) return;
- const skeleton = this._sheetSkeletonManagerService.getWorksheetSkeleton(latestEditCellState.sheetId)?.skeleton;
+ const skeleton = this._sheetSkeletonManagerService.getWorksheetSkeleton(editCellState.sheetId)?.skeleton;
if (!skeleton) return;
- const { row, column, scaleX, scaleY, position, canvasOffset, documentLayoutObject } = latestEditCellState;
+ const { row, column, scaleX, scaleY, position, canvasOffset, documentLayoutObject } = editCellState;
const maxSize = this._getEditorMaxSize(position, canvasOffset);
if (!maxSize) return;
const { height: clientHeight, width: clientWidth, scaleAdjust } = maxSize;
@@ -278,11 +280,11 @@ export class EditingRenderController extends Disposable implements IRenderModule
if (currentHeight !== height || currentWidth !== width) {
this._editorBridgeService.refreshEditCellPosition(true);
- const skeleton = this._getEditorSkeleton(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
- if (!skeleton) {
+ const docSkeleton = this._getEditorSkeleton(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
+ if (!docSkeleton) {
return;
}
- this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY, () => {
+ this._fitTextSize(position, canvasOffset, docSkeleton, documentLayoutObject, scaleX, scaleY, () => {
this._textSelectionManagerService.refreshSelection({
unitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
subUnitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
@@ -644,7 +646,7 @@ export class EditingRenderController extends Disposable implements IRenderModule
// Change `CursorChange` to changed status, when formula bar clicked.
this._cursorChange =
- eventType === DeviceInputEventType.PointerDown
+ (eventType === DeviceInputEventType.PointerDown || eventType === DeviceInputEventType.Dblclick)
? CursorChange.CursorChange
: CursorChange.StartEditor;
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index 1794838e82..ea8de1306c 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -193,7 +193,7 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
const ru = this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET);
if (!ru) return;
- const skeleton = ru.with(SheetSkeletonManagerService).getCurrentSkeleton();
+ const skeleton = ru.with(SheetSkeletonManagerService).getWorksheetSkeleton(currentEditCell.sheetId)?.skeleton;
const selectionRenderService = ru.with(ISheetSelectionRenderService);
if (!skeleton) return;
if (!this._currentEditCellState) return;