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: auto fill number error in right direction (#1311)

YuHong85f368fe0c52
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
index dcd78ee6c7..249104cb4a 100644
--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
@@ -55,159 +55,166 @@ const TEST_WORKBOOK_DATA = {
id: 'sheet1',
cellData: {
// Single Number
- '0': {
- '0': {
+ 0: {
+ 0: {
v: 1,
t: CellValueType.NUMBER,
},
- '1': {
+ 1: {
v: 2,
t: CellValueType.NUMBER,
},
},
// Single Number. descending
- '1': {
- '0': {
+ 1: {
+ 0: {
v: 2,
t: CellValueType.NUMBER,
},
- '1': {
+ 1: {
v: 1,
t: CellValueType.NUMBER,
},
},
// Extend Number
- '2': {
- '0': {
+ 2: {
+ 0: {
v: '第1',
t: CellValueType.STRING,
},
- '1': {
+ 1: {
v: '第2',
t: CellValueType.STRING,
},
},
// Chinese Number
- '3': {
- '0': {
+ 3: {
+ 0: {
v: '一',
t: CellValueType.STRING,
},
- '1': {
+ 1: {
v: '三',
t: CellValueType.STRING,
},
},
// Chinese Week
- '4': {
- '0': {
+ 4: {
+ 0: {
v: '星期一',
t: CellValueType.STRING,
},
- '1': {
+ 1: {
v: '星期三',
t: CellValueType.STRING,
},
},
// Loop Series
- '5': {
- '0': {
+ 5: {
+ 0: {
v: '甲',
t: CellValueType.STRING,
},
- '1': {
+ 1: {
v: '乙',
t: CellValueType.STRING,
},
},
// Other String
- '6': {
- '0': {
+ 6: {
+ 0: {
v: 'copy only',
t: CellValueType.STRING,
},
- '1': {
+ 1: {
v: 'no series',
t: CellValueType.STRING,
},
},
// Mixed Mode
- '7': {
- '0': {
+ 7: {
+ 0: {
v: 1,
t: CellValueType.NUMBER,
},
- '1': {
+ 1: {
v: 2,
t: CellValueType.NUMBER,
},
- '2': {
+ 2: {
v: '第1',
t: CellValueType.STRING,
},
- '3': {
+ 3: {
v: '第2',
t: CellValueType.STRING,
},
},
// db click to fill
- '10': {
- '0': {
+ 10: {
+ 0: {
v: 1,
t: CellValueType.NUMBER,
},
- '1': {
+ 1: {
v: 2,
t: CellValueType.NUMBER,
},
- '2': {
+ 2: {
v: 3,
t: CellValueType.NUMBER,
},
- '3': {
+ 3: {
v: 4,
t: CellValueType.NUMBER,
},
},
- '11': {
- '0': {
+ 11: {
+ 0: {
v: 2,
t: CellValueType.NUMBER,
},
- '2': {
+ 2: {
v: 3,
t: CellValueType.NUMBER,
},
},
- '12': {
- '0': {
+ 12: {
+ 0: {
v: 3,
t: CellValueType.NUMBER,
},
},
- '13': {
- '0': {
+ 13: {
+ 0: {
v: 4,
t: CellValueType.NUMBER,
},
},
// left direction & equal ratio & styles
- '14': {
- '2': {
+ 14: {
+ 2: {
v: 2,
t: CellValueType.NUMBER,
s: '_aRLOe',
},
- '3': {
+ 3: {
v: 4,
t: CellValueType.NUMBER,
},
- '4': {
+ 4: {
v: 8,
t: CellValueType.NUMBER,
s: '3UpAbI',
},
},
+ 16: {
+ 2: {
+ v: 2,
+ t: CellValueType.NUMBER,
+ s: '_aRLOe',
+ },
+ },
},
},
},
@@ -679,4 +686,77 @@ describe('Test auto fill rules in controller', () => {
});
});
});
+
+ describe('auto fill from single cell', async () => {
+ it('correct situation', async () => {
+ const workbook = get(IUniverInstanceService).getCurrentUniverSheetInstance();
+ if (!workbook) throw new Error('This is an error');
+ // test right
+ (autoFillController as any)._triggerAutoFill(
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 2,
+ },
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 4,
+ }
+ );
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(16, 3)?.v).toBe(3);
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(16, 4)?.v).toBe(4);
+ // test left
+ (autoFillController as any)._triggerAutoFill(
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 2,
+ },
+ {
+ startRow: 16,
+ startColumn: 0,
+ endRow: 16,
+ endColumn: 2,
+ }
+ );
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(16, 1)?.v).toBe(1);
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(16, 0)?.v).toBe(0);
+ // test up
+ (autoFillController as any)._triggerAutoFill(
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 2,
+ },
+ {
+ startRow: 15,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 2,
+ }
+ );
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(15, 2)?.v).toBe(1);
+ // test down
+ (autoFillController as any)._triggerAutoFill(
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 16,
+ endColumn: 2,
+ },
+ {
+ startRow: 16,
+ startColumn: 2,
+ endRow: 17,
+ endColumn: 2,
+ }
+ );
+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(17, 2)?.v).toBe(3);
+ });
+ });
});
diff --git a/packages/sheets-ui/src/services/auto-fill/tools.ts b/packages/sheets-ui/src/services/auto-fill/tools.ts
index d4e6fa3a5a..a7ecccd95f 100644
--- a/packages/sheets-ui/src/services/auto-fill/tools.ts
+++ b/packages/sheets-ui/src/services/auto-fill/tools.ts
@@ -404,7 +404,7 @@ export function fillSeries(data: Array<Nullable<ICellData>>, len: number, direct
const index = (i - 1) % data.length;
const d = Tools.deepClone(data[index]);
- const forward = direction === (Direction.DOWN || direction === Direction.RIGHT);
+ const forward = direction === Direction.DOWN || direction === Direction.RIGHT;
const y = forecast(data.length + i, dataNumArr, xArr, forward);
if (d) {