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

refactor(sheet): rename gitRangeDatas to getSelectionRanges #319

Merged
merged 2 commits into from
Oct 25, 2023
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 @@ -104,7 +104,7 @@ export class AutoHeightController {
};
}

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();

if (!selections?.length) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class HeaderMenuController extends Disposable {

const currentColumn = this._currentColumn;

const currentSelectionDatas = this._selectionManagerService.getRangeDatas();
const currentSelectionDatas = this._selectionManagerService.getSelectionRanges();

const selectedSelection = currentSelectionDatas?.find((data) => {
const { startRow, startColumn, endRow, endColumn } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ describe('Test style commands', () => {

expect(getMerge()?.length).toBe(0);
expect(await commandService.executeCommand(AddWorksheetMergeAllCommand.id)).toBeTruthy();
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 5, endColumn: 5 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 5, endColumn: 5, rangeType: RANGE_TYPE.NORMAL },
]);
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
expect(getMerge()?.length).toBe(0);
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 5, endColumn: 5 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 5, endColumn: 5, rangeType: RANGE_TYPE.NORMAL },
]);
});
});

Expand Down Expand Up @@ -119,7 +123,12 @@ describe('Test style commands', () => {
expect(getMerge()?.length).toBe(0);
expect(await commandService.executeCommand(AddWorksheetMergeVerticalCommand.id)).toBeTruthy();
expect(getMerge()?.length).toBe(6);
expect(getMerge()?.[0]).toStrictEqual({ startRow: 0, startColumn: 0, endColumn: 0, endRow: 5 });
expect(getMerge()?.[0]).toStrictEqual({
startRow: 0,
startColumn: 0,
endColumn: 0,
endRow: 5,
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ describe('Test clear selection content commands', () => {

// set merge cell
expect(await commandService.executeCommand(AddWorksheetMergeCommand.id)).toBeTruthy();
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },
]);

// clear formats with merged cells
expect(await commandService.executeCommand(ClearSelectionFormatCommand.id)).toBeTruthy();
Expand All @@ -235,7 +237,9 @@ describe('Test clear selection content commands', () => {
expect(getStyle()).toStrictEqual({
ff: 'Arial',
});
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },
]);
// redo
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
expect(getValue()).toStrictEqual({
Expand Down Expand Up @@ -365,7 +369,9 @@ describe('Test clear selection content commands', () => {

// set merge cell
expect(await commandService.executeCommand(AddWorksheetMergeCommand.id)).toBeTruthy();
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },
]);

// clear all with merged cells
expect(await commandService.executeCommand(ClearSelectionAllCommand.id)).toBeTruthy();
Expand All @@ -379,7 +385,9 @@ describe('Test clear selection content commands', () => {
expect(getStyle()).toStrictEqual({
ff: 'Arial',
});
expect(getMerge()).toStrictEqual([{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }]);
expect(getMerge()).toStrictEqual([
{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },
]);
// redo
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
expect(getValue()).toStrictEqual({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ export const AddWorksheetMergeCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selections = selectionManagerService.getRangeDatas();
if (!selections?.length) return false;

const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}

const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
const workbook = univerInstanceService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
const worksheet = workbook?.getSheetBySheetId(worksheetId);
if (!worksheet) {
return false;
}

let ranges = selections;

if (params && params.value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ClearSelectionAllCommand: ICommand = {
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ClearSelectionContentCommand: ICommand = {
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ClearSelectionFormatCommand: ICommand = {
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CopyFormatToRangeCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) return false;
const originRange = selections[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const CopyRangeToCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) return false;
const originRange = selections[0];
const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CopyValuesToRangeCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) return false;
const originRange = selections[0];
const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DeleteRangeMoveLeftCommand: ICommand = {

.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
const range = selectionManagerService.getSelectionRanges();
if (!range?.length) return false;

const workbook = univerInstanceService.getUniverSheetInstance(workbookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DeleteRangeMoveUpCommand: ICommand = {

.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
const range = selectionManagerService.getSelectionRanges();
if (!range?.length) return false;

const workbook = univerInstanceService.getUniverSheetInstance(workbookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const InsertRangeMoveDownCommand: ICommand = {

.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
const range = selectionManagerService.getSelectionRanges();
if (!range?.length) return false;

const workbook = univerInstanceService.getUniverSheetInstance(workbookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const InsertRangeMoveRightCommand: ICommand = {

const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
const range = selectionManagerService.getRangeDatas();
const range = selectionManagerService.getSelectionRanges();
if (!range?.length) return false;

const workbook = univerInstanceService.getUniverSheetInstance(workbookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const MoveRangeToCommand: ICommand = {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SelectionManagerService);

const originRange = selectionManagerService.getRangeDatas()?.[0];
const originRange = selectionManagerService.getSelectionRanges()?.[0];
if (!originRange) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const RemoveWorksheetMergeCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) return false;
const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = univerInstanceService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const SetBorderCommand: ICommand = {
const selectionManagerService = accessor.get(SelectionManagerService);
const borderStyleManagerService = accessor.get(BorderStyleManagerService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
const workbook = univerInstanceService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const SetBorderCommand: ICommand = {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SelectionManagerService);

const range = params.range || selectionManagerService.getRangeDatas()?.[0];
const range = params.range || selectionManagerService.getSelectionRanges()?.[0];
if (!range) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SetRangeFormattedValueCommand: ICommand = {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SelectionManagerService);

const ranges = selectionManagerService.getRangeDatas();
const ranges = selectionManagerService.getSelectionRanges();
if (!ranges?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const SetRangeValuesCommand: ICommand = {
.getSheetId(),
} = params;

const currentSelections = range ? [range] : selectionManagerService.getRangeDatas();
const currentSelections = range ? [range] : selectionManagerService.getSelectionRanges();
if (!currentSelections || !currentSelections.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const SetStyleCommand: ICommand<ISetStyleParams<unknown>> = {
const selectionManagerService = accessor.get(SelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const ranges = selectionManagerService.getRangeDatas();
const ranges = selectionManagerService.getSelectionRanges();
if (!ranges?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const SetColWidthCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const SetRowHeightCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const TrimWhitespaceCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = selectionManagerService.getRangeDatas();
const selections = selectionManagerService.getSelectionRanges();
if (!selections?.length) return false;

const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class SelectionManagerService implements IDisposable {
if (this._currentSelection == null) {
return;
}
this._currentSelection.pluginName = NORMAL_SELECTION_PLUGIN_NAME;

this._currentSelection.pluginName = NORMAL_SELECTION_PLUGIN_NAME;
this.refresh(this._currentSelection);
}

Expand All @@ -91,6 +91,7 @@ export class SelectionManagerService implements IDisposable {
if (this._currentSelection == null) {
return;
}

this.refresh(this._currentSelection);
}

Expand Down Expand Up @@ -120,22 +121,13 @@ export class SelectionManagerService implements IDisposable {
return this._getSelectionDatas(this._currentSelection);
}

/** @deprecated use `getSelections` instead */
getRangeDatas(): Nullable<IRange[]> {
getSelectionRanges(): Nullable<IRange[]> {
const selectionDataList = this.getSelections();
if (selectionDataList == null) {
return;
}
return selectionDataList.map((selectionData: ISelectionWithStyle) => {
const range = selectionData.range;
const { startRow, startColumn, endRow, endColumn } = range;
return {
startRow,
startColumn,
endRow,
endColumn,
};
});

return selectionDataList.map((selectionData: ISelectionWithStyle) => selectionData.range);
}

getFirst(): Readonly<Nullable<ISelectionWithStyle>> {
Expand Down
Loading