Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheets): bugfix for data-validation and hyper-link #2527

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/types/interfaces/i-cell-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
getColorStyle,
HorizontalAlign,
IContextService,
isEmptyCell,
isCellCoverable,
isNullCell,
isWhiteColor,
LocaleService,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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;
Expand Down Expand Up @@ -336,6 +336,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
};
return validator?.canvasRender?.calcCellAutoHeight?.(info);
},
coverable: (cell?.coverable ?? true) && !(rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE),
});
},
}
Expand Down
2 changes: 2 additions & 0 deletions packages/sheets-hyper-link-ui/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export function serializeUrl(urlStr: string) {
) {
return url.hash;
}

return transformedUrl;
}

return urlStr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
Loading