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-hyper-link): link ref range behavior error #3862

Merged
merged 3 commits into from
Oct 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import type { IDisposable, IDocumentData, IRange, Nullable, Workbook } from '@univerjs/core';
import type { EffectRefRangeParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { CustomRangeType, Disposable, DisposableCollection, ICommandService, Inject, isValidRange, IUniverInstanceService, ObjectMatrix, Tools, UniverInstanceType } from '@univerjs/core';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { CustomRangeType, Disposable, DisposableCollection, ICommandService, Inject, isValidRange, IUniverInstanceService, ObjectMatrix, UniverInstanceType } from '@univerjs/core';
import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
import { handleDefaultRangeChangeWithEffectRefCommands, RefRangeService, SetRangeValuesMutation } from '@univerjs/sheets';
import { RefRangeService, SetRangeValuesMutation } from '@univerjs/sheets';
import { ERROR_RANGE } from '@univerjs/sheets-hyper-link';

export class SheetsHyperLinkRichTextRefRangeController extends Disposable {
Expand Down Expand Up @@ -81,62 +81,6 @@ export class SheetsHyperLinkRichTextRefRangeController extends Disposable {

private _registerRange(unitId: string, subUnitId: string, row: number, col: number, p: IDocumentData) {
const map = this._enusreMap(unitId, subUnitId);
const data = Tools.deepClone(p);
const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
const dataCopy = Tools.deepClone(data);
dataCopy.body?.customRanges?.forEach((customRange) => {
if (customRange.rangeType === CustomRangeType.HYPERLINK) {
const payload = customRange.properties?.url;
const range = this._isLegalRangeUrl(unitId, payload);
if (range) {
const resultRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
const newPayload = `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : ERROR_RANGE}`;
customRange.properties!.url = newPayload;
}
}
});
const position = handleDefaultRangeChangeWithEffectRefCommands({ startRow: row, endRow: row, startColumn: col, endColumn: col }, commandInfo);

if (!position) {
return {
redos: [],
undos: [],
};
}

return {
redos: [{
id: SetRangeValuesMutation.id,
params: {
unitId,
subUnitId,
cellValue: {
[position.startRow]: {
[position.startColumn]: {
p: dataCopy,
},
},
},
},
}],
undos: [
{
id: SetRangeValuesMutation.id,
params: {
unitId,
subUnitId,
cellValue: {
[row]: {
[col]: {
p: data,
},
},
},
},
},
],
};
};

if (p.body?.customRanges?.some((customRange) => customRange.rangeType === CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, customRange.properties?.url))) {
const disposableCollection = new DisposableCollection();
Expand All @@ -145,7 +89,9 @@ export class SheetsHyperLinkRichTextRefRangeController extends Disposable {
const payload = customRange.properties?.url;
const range = this._isLegalRangeUrl(unitId, payload);
if (range) {
disposableCollection.add(this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
disposableCollection.add(this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => {
customRange.properties!.url = `#gid=${subUnitId}&range=${after ? serializeRange(after) : ERROR_RANGE}`;
}));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export const CellLinkEdit = () => {
</FormLayout>
)
: null}
<FormLayout label={localeService.t('hyperLink.form.type')} contentStyle={{ marginBottom: 0 }}>
<FormLayout label={localeService.t('hyperLink.form.type')}>
<Select
options={linkTypeOptions}
value={type}
Expand Down
Loading