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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(rangeselector): add param to keep rang selector ref always with sheetname (#5774)
VicKun1b5867061bd6
diff --git a/packages/sheets-formula-ui/src/views/range-selector/hooks/use-selection-change.ts b/packages/sheets-formula-ui/src/views/range-selector/hooks/use-selection-change.tsindex 9dd5c126a9..83898aad00 100644--- a/packages/sheets-formula-ui/src/views/range-selector/hooks/use-selection-change.ts+++ b/packages/sheets-formula-ui/src/views/range-selector/hooks/use-selection-change.ts@@ -21,9 +21,17 @@ import { SheetsSelectionsService } from '@univerjs/sheets';import { useDependency, useEvent } from '@univerjs/ui';import { useEffect } from 'react';-export function useRangeSelectorSelectionChange(opts: { supportAcrossSheet?: boolean; unitId: string; subUnitId: string; onChange: (ranges: IUnitRangeName[], isStart: boolean) => void }) {+interface IRangeSelectorSelectionChangeProps {+ supportAcrossSheet?: boolean;+ keepSheetReference?: boolean;+ unitId: string;+ subUnitId: string;+ onChange: (ranges: IUnitRangeName[], isStart: boolean) => void;+}++export function useRangeSelectorSelectionChange(opts: IRangeSelectorSelectionChangeProps) {const sheetsSelectionsService = useDependency(SheetsSelectionsService);- const { supportAcrossSheet = false, unitId, subUnitId, onChange: _onChange } = opts;+ const { supportAcrossSheet = false, keepSheetReference = false, unitId, subUnitId, onChange: _onChange } = opts;const univerInstanceService = useDependency(IUniverInstanceService);const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const onChange = useEvent(_onChange);@@ -33,10 +41,11 @@ export function useRangeSelectorSelectionChange(opts: { supportAcrossSheet?: booif (!currentSheet) return;if (!supportAcrossSheet && currentSheet.getSheetId() !== subUnitId) return;if (!selections?.length) return;+ const sheetName = keepSheetReference ? currentSheet.getName() : (currentSheet.getSheetId() === subUnitId ? '' : currentSheet.getName());const ranges = selections.map((item) => ({range: item.range,unitId,- sheetName: currentSheet.getSheetId() === subUnitId ? '' : currentSheet.getName(),+ sheetName,}));onChange(ranges, isStart);diff --git a/packages/sheets-formula-ui/src/views/range-selector/index.tsx b/packages/sheets-formula-ui/src/views/range-selector/index.tsxindex aac848336f..54ee86e96c 100644--- a/packages/sheets-formula-ui/src/views/range-selector/index.tsx+++ b/packages/sheets-formula-ui/src/views/range-selector/index.tsx@@ -46,6 +46,10 @@ export interface IRangeSelectorProps extends IRichTextEditorProps {subUnitId: string;maxRangeCount?: number;supportAcrossSheet?: boolean;+ /**+ * always return range ref with sheet name, default: false+ */+ keepSheetReference?: boolean;selectorRef?: React.RefObject<IRangeSelectorInstance | null>;onVerify?: (res: boolean, rangeText: string) => void;onRangeSelectorDialogVisibleChange?: (visible: boolean) => void;@@ -61,6 +65,7 @@ export interface IRangeSelectorDialogProps {subUnitId: string;maxRangeCount?: number;supportAcrossSheet?: boolean;+ keepSheetReference?: boolean;onConfirm: (ranges: IUnitRangeName[]) => void;onClose: () => void;onShowBySelection?: (ranges: IUnitRangeName[]) => boolean;@@ -74,6 +79,7 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {subUnitId,maxRangeCount = Infinity,supportAcrossSheet,+ keepSheetReference,onConfirm,onClose,onShowBySelection,@@ -114,6 +120,7 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {unitId,subUnitId,supportAcrossSheet,+ keepSheetReference,onChange: (selections, isStart) => {if (!visible) {if (onShowBySelection?.(selections)) {@@ -236,6 +243,7 @@ export function RangeSelector(props: IRangeSelectorProps) {subUnitId,maxRangeCount,supportAcrossSheet,+ keepSheetReference,autoFocus,onChange,onRangeSelectorDialogVisibleChange,@@ -365,6 +373,7 @@ export function RangeSelector(props: IRangeSelectorProps) {setRangeSelectorRanges([]);}}supportAcrossSheet={supportAcrossSheet}+ keepSheetReference={keepSheetReference}onShowBySelection={(ranges: IUnitRangeName[]) => {if (focusing || forceShowDialogWhenSelectionChanged) {setRangeSelectorRanges(ranges);