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
feat(sheets-ui): configure selection animation (#8144)
白熱f55562322351
diff --git a/packages/sheets-ui/src/config/config.ts b/packages/sheets-ui/src/config/config.tsindex 56452ab8f5..d7e18a6f2b 100644--- a/packages/sheets-ui/src/config/config.ts+++ b/packages/sheets-ui/src/config/config.ts@@ -35,6 +35,13 @@ export interface IUniverSheetsUIConfig {*/allowArrowKeyWrapOnSheetBoundary?: boolean;+ /**+ * Whether to animate the selection outline when clicking between cells on desktop.+ * The system preference for reduced motion takes precedence.+ * @default true+ */+ selectionAnimation?: boolean;+/*** The maximum count of rows triggering auto height. This is used to avoid performance issue.* @default 1000diff --git a/packages/sheets-ui/src/services/selection/__tests__/selection-render.service.spec.ts b/packages/sheets-ui/src/services/selection/__tests__/selection-render.service.spec.tsindex 81f4873a41..472b85450b 100644--- a/packages/sheets-ui/src/services/selection/__tests__/selection-render.service.spec.ts+++ b/packages/sheets-ui/src/services/selection/__tests__/selection-render.service.spec.ts@@ -19,6 +19,7 @@ import type { IPointerEvent, IRenderContext, SpreadsheetSkeleton } from '@univerimport type { ISelectionWithStyle } from '@univerjs/sheets';import {ICommandService,+ IConfigService,LocaleService,LocaleType,RANGE_TYPE,@@ -51,8 +52,8 @@ import {UIRuntimeScopeService,} from '@univerjs/ui';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { SHEET_COMPONENT_MAIN_LAYER_INDEX, SHEET_VIEW_KEY } from '../../../common/keys';+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../../config/config';import { createRenderTestBed } from '../../../controllers/render-controllers/__tests__/render-test-bed';import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';import { SheetSelectionRenderService } from '../selection-render.service';@@ -349,7 +350,11 @@ describe('SheetSelectionRenderService pointer gestures with real render providerreturn { injector, workbook, render, spreadsheet, service, skeleton, getSelections, eventAt, click };}- it.each([20, 1_000_000])('animates clicks without delaying selection or invalidating sheet content with %i rows', (rowCount) => {+ it.each([+ { rowCount: 20, selectionAnimation: undefined },+ { rowCount: 1_000_000, selectionAnimation: true },+ ])('animates clicks without delaying selection or invalidating sheet content with $rowCount rows', ({ rowCount, selectionAnimation }) => {+ univer.__getInjector().get(IConfigService).setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { selectionAnimation });const { click, service, skeleton, render, getSelections } = createSelectionTestBed([], rowCount);click(1, 1);vi.advanceTimersByTime(160);@@ -386,6 +391,22 @@ describe('SheetSelectionRenderService pointer gestures with real render providerexpect(translate).not.toHaveBeenCalled();});+ it('updates the selection immediately without subsequent motion when animation is disabled', () => {+ univer.__getInjector().get(IConfigService).setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { selectionAnimation: false });+ const { click, render, getSelections } = createSelectionTestBed();+ const service = render.with(SheetSelectionRenderService);+ click(1, 1);+ click(5, 4);++ const control = service.getActiveSelectionControl()!;+ expect(getSelections()[0].range).toMatchObject({ startRow: 5, endRow: 5, startColumn: 4, endColumn: 4 });+ expect(control.selectionShape.left).toBe(control.getRange().startX);+ expect(control.selectionShape.top).toBe(control.getRange().startY);+ const translate = vi.spyOn(control.selectionShape, 'translate');+ vi.advanceTimersByTime(300);+ expect(translate).not.toHaveBeenCalled();+ });+it('retargets from the visible position and cancels motion when dragging or disposing', () => {const { click, service, eventAt, spreadsheet, render } = createSelectionTestBed();click(1, 1);@@ -419,6 +440,7 @@ describe('SheetSelectionRenderService pointer gestures with real render provider});it('resizes merged cell outlines at constant stroke width and respects reduced motion', () => {+ univer.__getInjector().get(IConfigService).setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { selectionAnimation: true });const { click, service } = createSelectionTestBed([{ startRow: 3, endRow: 4, startColumn: 3, endColumn: 5 }]);click(1, 1);vi.advanceTimersByTime(160);diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.tsindex 617d042e66..128bc95888 100644--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts@@ -22,10 +22,9 @@ import type {ISetSelectionsOperationParams,WorkbookSelectionModel,} from '@univerjs/sheets';-import type { ISheetObjectParam } from '../../controllers/utils/component-tools';-import type { SelectionControl } from './selection-control';import {ICommandService,+ IConfigService,IContextService,ILogService,Inject,@@ -48,7 +47,10 @@ import {} from '@univerjs/sheets';import { IShortcutService } from '@univerjs/ui';import { distinctUntilChanged, merge, startWith } from 'rxjs';-+import type { IUniverSheetsUIConfig } from '../../config/config';+import type { ISheetObjectParam } from '../../controllers/utils/component-tools';+import type { SelectionControl } from './selection-control';+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../config/config';import { getCoordByOffset, getSheetObject } from '../../controllers/utils/component-tools';import { isThisColSelected, isThisRowSelected } from '../../controllers/utils/selections-tools';import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';@@ -472,7 +474,8 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService impllet activeControl = this.getActiveSelectionControl();if (activeControl && this._canAnimateSelection(evt, activeControl, cursorRange)) {- activeControl.updateRangeBySelectionWithCoord(selectionWithCoord, this._skeleton, true);+ const config = this._injector.get(IConfigService).getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);+ activeControl.updateRangeBySelectionWithCoord(selectionWithCoord, this._skeleton, config?.selectionAnimation !== false);return activeControl;}this._checkClearPreviousControls(evt);diff --git a/presets/packages/preset-sheets-core/src/preset.ts b/presets/packages/preset-sheets-core/src/preset.tsindex b01b361b8d..7fe1390d69 100644--- a/presets/packages/preset-sheets-core/src/preset.ts+++ b/presets/packages/preset-sheets-core/src/preset.ts@@ -142,6 +142,7 @@ export function UniverSheetsCorePreset(config: Partial<IUniverSheetsCorePresetCoformulaBar,footer,allowArrowKeyWrapOnSheetBoundary: sheets?.allowArrowKeyWrapOnSheetBoundary,+ selectionAnimation: sheets?.selectionAnimation,maxAutoHeightCount: sheets?.maxAutoHeightCount,enableFillHandle: sheets?.enableFillHandle,clipboardConfig: sheets?.clipboardConfig,diff --git a/presets/packages/preset-sheets-core/src/types.ts b/presets/packages/preset-sheets-core/src/types.tsindex 2993601737..38d969dca9 100644--- a/presets/packages/preset-sheets-core/src/types.ts+++ b/presets/packages/preset-sheets-core/src/types.ts@@ -49,5 +49,6 @@ export interface IUniverSheetsPresetConfig extends| 'disableForceStringAlert'| 'disableForceStringMark'| 'allowArrowKeyWrapOnSheetBoundary'+ | 'selectionAnimation'> {}