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.

feat(sheets-ui): configure fill handle visibility (#8145)

白熱3171e2eb957e
diff --git a/packages/sheets-ui/src/config/config.ts b/packages/sheets-ui/src/config/config.ts
index 7bcd7981e2..590152115b 100644
--- a/packages/sheets-ui/src/config/config.ts
+++ b/packages/sheets-ui/src/config/config.ts
@@ -41,6 +41,13 @@ export interface IUniverSheetsUIConfig {
*/
maxAutoHeightCount?: number;
+ /**
+ * Whether to show the desktop fill handle for dragging and double-click filling.
+ * Does not affect fill commands or Facade APIs.
+ * @default true
+ */
+ enableFillHandle?: boolean;
+
/**
* Whether to show the formula bar.
*/
diff --git a/packages/sheets-ui/src/services/selection/__tests__/base-selection-render.service.spec.ts b/packages/sheets-ui/src/services/selection/__tests__/base-selection-render.service.spec.ts
index 8a0b997aa6..86223d0f92 100644
--- a/packages/sheets-ui/src/services/selection/__tests__/base-selection-render.service.spec.ts
+++ b/packages/sheets-ui/src/services/selection/__tests__/base-selection-render.service.spec.ts
@@ -39,6 +39,7 @@ import {
UIRuntimeScopeService,
} from '@univerjs/ui';
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../../config/config';
import {
createFakeEngine,
createFakeScene,
@@ -338,6 +339,21 @@ describe('BaseSelectionRenderService', () => {
expect(service.inRefSelectionMode()).toBe(false);
});
+ it.each([undefined, true, false])('keeps selection updates working with enableFillHandle=%s', (enableFillHandle) => {
+ const { injector, service } = createSelectionRenderService();
+ injector.get(IConfigService).setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { enableFillHandle });
+ service.changeRuntimeForTest();
+
+ service.resetSelectionsByModelData([selections[0]]);
+ expect(service.getActiveSelectionControl()!.fillControl.visible).toBe(enableFillHandle !== false);
+
+ service.resetSelectionsByModelData([selections[1]]);
+ const control = service.getActiveSelectionControl()!;
+ expect(control.getRange()).toMatchObject(selections[1].range);
+ expect(control.selectionShape.visible).toBe(true);
+ expect(control.fillControl.visible).toBe(enableFillHandle !== false);
+ });
+
it('chooses the visible viewport for frozen row and column selections', () => {
const { service } = createSelectionRenderService();
service.changeRuntimeForTest({
diff --git a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts b/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
index 4a3557731d..fb32c204e1 100644
--- a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
+++ b/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
@@ -37,11 +37,11 @@ import type { ISelectionStyle, ISelectionWithCoord, ISelectionWithStyle } from '
import type { Theme } from '@univerjs/themes';
import type { IShortcutService } from '@univerjs/ui';
import type { Observable, Subscription } from 'rxjs';
-import type { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import {
convertCellToRange,
createIdentifier,
Disposable,
+ IConfigService,
InterceptorManager,
RANGE_TYPE,
ThemeService,
@@ -55,8 +55,11 @@ import {
} from '@univerjs/sheets';
import { IPlatformService } from '@univerjs/ui';
import { BehaviorSubject, Subject } from 'rxjs';
+import type { IUniverSheetsUIConfig } from '../../config/config';
+import type { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { SHEET_COMPONENT_SELECTION_LAYER_INDEX } from '../../common/keys';
import { isSheetContextMenuGesture, isSheetMultiSelectModifier } from '../../common/selection-input';
+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../config/config';
import { genNormalSelectionStyle, RANGE_FILL_PERMISSION_CHECK, RANGE_MOVE_PERMISSION_CHECK } from './const';
import { SelectionControl } from './selection-control';
import { SelectionLayer } from './selection-layer';
@@ -265,7 +268,9 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
columnHeaderHeight,
columnHeaderHeightAndMarginTop,
} = skeleton;
+ const config = this._injector.get(IConfigService).getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
const control = new SelectionControl(scene, zIndex, this._selectionTheme, {
+ enableAutoFill: config?.enableFillHandle,
highlightHeader: this._highlightHeader,
rowHeaderWidth,
columnHeaderHeight,
diff --git a/presets/packages/preset-sheets-core/src/preset.ts b/presets/packages/preset-sheets-core/src/preset.ts
index 137ecc7a83..97f17240e8 100644
--- a/presets/packages/preset-sheets-core/src/preset.ts
+++ b/presets/packages/preset-sheets-core/src/preset.ts
@@ -19,7 +19,6 @@ import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';
import type { IUniverSheetsNumfmtConfig } from '@univerjs/sheets-numfmt';
import type { IUniverSheetsUIConfig } from '@univerjs/sheets-ui';
import type { IUniverUIConfig } from '@univerjs/ui';
-import type { IUniverDocsPresetConfig, IUniverFormulaConfig, IUniverSheetsPresetConfig } from './types';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
@@ -33,7 +32,7 @@ import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsNumfmtUIPlugin } from '@univerjs/sheets-numfmt-ui';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverUIPlugin } from '@univerjs/ui';
-
+import type { IUniverDocsPresetConfig, IUniverFormulaConfig, IUniverSheetsPresetConfig } from './types';
// NOTE: here we copy code from everything.ts. That file (along with the package itself) would be removed in the future.
import '@univerjs/network/facade';
import '@univerjs/sheets/facade';
@@ -144,6 +143,7 @@ export function UniverSheetsCorePreset(config: Partial<IUniverSheetsCorePresetCo
footer,
allowArrowKeyWrapOnSheetBoundary: sheets?.allowArrowKeyWrapOnSheetBoundary,
maxAutoHeightCount: sheets?.maxAutoHeightCount,
+ enableFillHandle: sheets?.enableFillHandle,
clipboardConfig: sheets?.clipboardConfig,
scrollConfig: sheets?.scrollConfig,
protectedRangeShadow: sheets?.protectedRangeShadow ?? true,
diff --git a/presets/packages/preset-sheets-core/src/types.ts b/presets/packages/preset-sheets-core/src/types.ts
index dd91116761..c21700dfcf 100644
--- a/presets/packages/preset-sheets-core/src/types.ts
+++ b/presets/packages/preset-sheets-core/src/types.ts
@@ -40,6 +40,7 @@ export interface IUniverSheetsPresetConfig extends
Pick<
IUniverSheetsUIConfig,
'maxAutoHeightCount'
+ | 'enableFillHandle'
| 'clipboardConfig'
| 'scrollConfig'
| 'protectedRangeShadow'