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): bugfix for data-validation and hyper-link (#2527)

zhangw389e65bcb669
diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts
index fd140dad85..7255db7b97 100644
--- a/packages/core/src/shared/common.ts
+++ b/packages/core/src/shared/common.ts
@@ -23,7 +23,7 @@ import {
WrapStrategy,
} from '../types/enum';
import { type IRange, RANGE_TYPE } from '../types/interfaces';
-import type { ICellData } from '../types/interfaces/i-cell-data';
+import type { ICellData, ICellDataForSheetInterceptor } from '../types/interfaces/i-cell-data';
import type { IDocumentData } from '../types/interfaces/i-document-data';
import type { IRangeWithCoord, ISelectionCell, ISelectionCellWithCoord } from '../types/interfaces/i-selection-data';
import type { IColorStyle, IStyleData } from '../types/interfaces/i-style-data';
@@ -132,6 +132,10 @@ export function isEmptyCell(cell: Nullable<ICellData>) {
return false;
}
+export function isCellCoverable(cell: Nullable<ICellDataForSheetInterceptor>) {
+ return isEmptyCell(cell) && cell?.coverable !== false;
+}
+
export function getColorStyle(color: Nullable<IColorStyle>): Nullable<string> {
if (color) {
if (color.rgb) {
diff --git a/packages/core/src/types/interfaces/i-cell-data.ts b/packages/core/src/types/interfaces/i-cell-data.ts
index 6bf856b19a..f03f870f86 100644
--- a/packages/core/src/types/interfaces/i-cell-data.ts
+++ b/packages/core/src/types/interfaces/i-cell-data.ts
@@ -83,6 +83,10 @@ export interface ICellDataForSheetInterceptor extends ICellData {
markers?: ICellMarks;
customRender?: Nullable<ICellCustomRender[]>;
interceptorAutoHeight?: number;
+ /**
+ * can cell be covered when sibling is overflow
+ */
+ coverable?: boolean;
}
export function isICellData(value: any): value is ICellData {
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
index 627426f566..4f07e7ff43 100644
--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts
+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
@@ -27,7 +27,7 @@ import {
getColorStyle,
HorizontalAlign,
IContextService,
- isEmptyCell,
+ isCellCoverable,
isNullCell,
isWhiteColor,
LocaleService,
@@ -1521,7 +1521,7 @@ export class SpreadsheetSkeleton extends Skeleton {
for (let i = startColumn; i >= endColumn; i--) {
const column = i;
const cell = this._worksheet?.getCell(row, column);
- if ((!isEmptyCell(cell) && column !== startColumn) || this.intersectMergeRange(row, column)) {
+ if ((!isCellCoverable(cell) && column !== startColumn) || this.intersectMergeRange(row, column)) {
if (column === startColumn) {
return column;
}
@@ -1550,7 +1550,7 @@ export class SpreadsheetSkeleton extends Skeleton {
for (let i = startColumn; i <= endColumn; i++) {
const column = i;
const cell = this._worksheet?.getCell(row, column);
- if ((!isEmptyCell(cell) && column !== startColumn) || this.intersectMergeRange(row, column)) {
+ if ((!isCellCoverable(cell) && column !== startColumn) || this.intersectMergeRange(row, column)) {
if (column === startColumn) {
return column;
}
diff --git a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
index a58b34b0f3..a0545a7f4b 100644
--- a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
+++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
@@ -213,7 +213,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
INTERCEPTOR_POINT.CELL_CONTENT,
{
priority: 200,
- // eslint-disable-next-line max-lines-per-function
+ // eslint-disable-next-line max-lines-per-function, complexity
handler: (cell, pos, next) => {
const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
@@ -340,6 +340,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
};
return validator?.canvasRender?.calcCellAutoHeight?.(info);
},
+ coverable: (cell?.coverable ?? true) && !(rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE),
});
},
}
diff --git a/packages/sheets-hyper-link-ui/src/common/util.ts b/packages/sheets-hyper-link-ui/src/common/util.ts
index 4b38c56611..43f1a39b1d 100644
--- a/packages/sheets-hyper-link-ui/src/common/util.ts
+++ b/packages/sheets-hyper-link-ui/src/common/util.ts
@@ -56,6 +56,8 @@ export function serializeUrl(urlStr: string) {
) {
return url.hash;
}
+
+ return transformedUrl;
}
return urlStr;
diff --git a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
index 5fab1a0c9e..7b38d1a8ac 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
@@ -18,7 +18,7 @@ import type { IMutationInfo } from '@univerjs/core';
import { CellValueType, Disposable, IUniverInstanceService, LifecycleStages, ObjectMatrix, OnLifecycle, Range, Tools } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
-import { ClearSelectionAllCommand, ClearSelectionContentCommand, getSheetCommandTarget, SelectionManagerService, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService } from '@univerjs/sheets';
+import { ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, getSheetCommandTarget, SelectionManagerService, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService } from '@univerjs/sheets';
import type { IAddHyperLinkCommandParams, IUpdateHyperLinkCommandParams } from '@univerjs/sheets-hyper-link';
import { AddHyperLinkCommand, AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkCommand } from '@univerjs/sheets-hyper-link';
import { isLegalLink, serializeUrl } from '../common/util';
@@ -211,7 +211,11 @@ export class SheetHyperLinkSetRangeController extends Disposable {
private _initClearSelectionCommandInterceptor() {
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
getMutations: (command) => {
- if (command.id === ClearSelectionContentCommand.id || command.id === ClearSelectionAllCommand.id) {
+ if (
+ command.id === ClearSelectionContentCommand.id ||
+ command.id === ClearSelectionAllCommand.id ||
+ command.id === ClearSelectionFormatCommand.id
+ ) {
const redos: IMutationInfo[] = [];
const undos: IMutationInfo[] = [];
const selection = this._selectionManagerService.getFirst();