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): modify selection when need to add one (#4513)

zhangw46e9e1cf839b
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/hooks/useSheetSelectionChange.ts b/packages/sheets-formula-ui/src/views/formula-editor/hooks/useSheetSelectionChange.ts
index 0fb09e503b..4590060186 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/hooks/useSheetSelectionChange.ts
+++ b/packages/sheets-formula-ui/src/views/formula-editor/hooks/useSheetSelectionChange.ts
@@ -37,12 +37,13 @@ import { getOffsetFromSequenceNodes } from '../../range-selector/utils/getOffset
import { sequenceNodeToText } from '../../range-selector/utils/sequenceNodeToText';
import { unitRangesToText } from '../../range-selector/utils/unitRangesToText';
import { useStateRef } from '../hooks/useStateRef';
-import { useSelectionAdd } from './useSelectionAdd';
+import { FormulaSelectingType } from './useFormulaSelection';
const noop = (() => { }) as any;
export const useSheetSelectionChange = (
isNeed: boolean,
isFocus: boolean,
+ isSelecting: FormulaSelectingType,
unitId: string,
subUnitId: string,
sequenceNodes: INode[],
@@ -58,7 +59,6 @@ export const useSheetSelectionChange = (
const sequenceNodesRef = useStateRef(sequenceNodes);
const docSelectionManagerService = useDependency(DocSelectionManagerService);
const themeService = useDependency(ThemeService);
- const { getIsNeedAddSelection } = useSelectionAdd(unitId, editor);
const workbook = univerInstanceService.getUnit<Workbook>(unitId);
const getSheetNameById = useEvent((sheetId: string) => workbook?.getSheetBySheetId(sheetId)?.getName() ?? '');
@@ -70,11 +70,11 @@ export const useSheetSelectionChange = (
const sheetSkeletonManagerService = render?.with(SheetSkeletonManagerService);
const refSelectionsService = useDependency(IRefSelectionsService);
const isScalingRef = useRef(false);
+ const isSelectingRef = useRef(isSelecting);
+ isSelectingRef.current = isSelecting;
const scalingOptionRef = useRef<{ result: string; offset: number }>();
- useEffect(() => {}, []);
-
useEffect(() => {
if (refSelectionsRenderService && isNeed) {
let isFirst = true;
@@ -93,7 +93,7 @@ export const useSheetSelectionChange = (
const sequenceNodes = [...sequenceNodesRef.current];
const nodeIndex = findIndexFromSequenceNodes(sequenceNodes, offset, false);
- if (getIsNeedAddSelection()) {
+ if (isSelectingRef.current === FormulaSelectingType.NEED_ADD) {
if (offset !== 0) {
if (nodeIndex === -1 && sequenceNodes.length) {
return;
@@ -202,7 +202,7 @@ export const useSheetSelectionChange = (
disposableCollection.dispose();
};
}
- }, [refSelectionsRenderService, editor, isSupportAcrossSheet, isNeed, sequenceNodesRef, getIsNeedAddSelection, subUnitId, unitId, getSheetNameById, sheetName, handleRangeChange, contextRef]);
+ }, [refSelectionsRenderService, editor, isSupportAcrossSheet, isNeed, sequenceNodesRef, subUnitId, unitId, getSheetNameById, sheetName, handleRangeChange, contextRef]);
useEffect(() => {
if (isFocus && refSelectionsRenderService && editor) {
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
index b84d5888da..431dfb0332 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
@@ -258,10 +258,10 @@ export function FormulaEditor(props: IFormulaEditorProps) {
checkScrollBar();
}
});
-
useSheetSelectionChange(
isFocus && Boolean(isSelecting && docFocusing),
isFocus,
+ isSelecting,
unitId,
subUnitId,
sequenceNodes,