Skip to content

Commit d6030bf

Browse files
committed
[WIP]
1 parent 85f2ecb commit d6030bf

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

packages/o-spreadsheet-engine/src/plugins/ui_stateful/clipboard.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export class ClipboardPlugin extends UIPlugin {
104104
}
105105
break;
106106
}
107+
case "COPY_PASTE_CELLS_ON_ZONE": {
108+
const zones = this.getters.getSelectedZones();
109+
if (zones.length > 1) {
110+
return CommandResult.InvalidCopyPasteSelection;
111+
}
112+
break;
113+
}
107114
case "INSERT_CELL": {
108115
const { cut, paste } = this.getInsertCellsTargets(cmd.zone, cmd.shiftDimension);
109116
const copiedData = this.copy(cut, "shiftCells");
@@ -212,6 +219,22 @@ export class ClipboardPlugin extends UIPlugin {
212219
});
213220
}
214221
break;
222+
case "COPY_PASTE_CELLS_ON_ZONE":
223+
{
224+
const zone = this.getters.getSelectedZone();
225+
const copyTarget = {
226+
...zone,
227+
right: zone.left,
228+
bottom: zone.top,
229+
};
230+
this.originSheetId = this.getters.getActiveSheetId();
231+
const copiedData = this.copy([copyTarget]);
232+
this.paste([zone], copiedData, {
233+
isCutOperation: false,
234+
selectTarget: true,
235+
});
236+
}
237+
break;
215238
case "CLEAN_CLIPBOARD_HIGHLIGHT":
216239
this.status = "invisible";
217240
break;

packages/o-spreadsheet-engine/src/types/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ export interface CopyPasteCellsOnLeftCommand {
860860
type: "COPY_PASTE_CELLS_ON_LEFT";
861861
}
862862

863+
export interface CopyPasteCellsOnZoneCommand {
864+
type: "COPY_PASTE_CELLS_ON_ZONE";
865+
}
866+
863867
export interface RepeatPasteCommand {
864868
type: "REPEAT_PASTE";
865869
target: Zone[];
@@ -1237,6 +1241,7 @@ export type LocalCommand =
12371241
| PasteCommand
12381242
| CopyPasteCellsAboveCommand
12391243
| CopyPasteCellsOnLeftCommand
1244+
| CopyPasteCellsOnZoneCommand
12401245
| RepeatPasteCommand
12411246
| CleanClipBoardHighlightCommand
12421247
| AutoFillCellCommand

src/actions/insert_actions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export const insertImage: ActionSpec = {
204204

205205
export const insertTable: ActionSpec = {
206206
name: () => _t("Table"),
207+
description: "Alt+T",
207208
execute: ACTIONS.INSERT_TABLE,
208209
isVisible: (env) =>
209210
ACTIONS.IS_SELECTION_CONTINUOUS(env) && !env.model.getters.getFirstTableInSelection(),
@@ -275,6 +276,7 @@ export const categoriesFunctionListMenuBuilder: ActionBuilder = () => {
275276

276277
export const insertLink: ActionSpec = {
277278
name: _t("Link"),
279+
description: "Ctrl+K",
278280
execute: ACTIONS.INSERT_LINK,
279281
icon: "o-spreadsheet-Icon.INSERT_LINK",
280282
};
@@ -336,6 +338,7 @@ export const insertDropdown: ActionSpec = {
336338

337339
export const insertSheet: ActionSpec = {
338340
name: _t("Insert sheet"),
341+
description: "Shift+F11",
339342
execute: (env) => {
340343
const activeSheetId = env.model.getters.getActiveSheetId();
341344
const position = env.model.getters.getSheetIds().indexOf(activeSheetId) + 1;

src/components/grid/grid.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
useRef,
1818
useState,
1919
} from "@odoo/owl";
20+
import { insertSheet, insertTable } from "../../actions/insert_actions";
2021
import {
2122
CREATE_IMAGE,
2223
INSERT_COLUMNS_BEFORE_ACTION,
@@ -361,6 +362,7 @@ export class Grid extends Component<Props, SpreadsheetChildEnv> {
361362
},
362363
"Ctrl+D": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ABOVE"),
363364
"Ctrl+R": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_LEFT"),
365+
"Ctrl+Enter": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_ZONE"),
364366
"Ctrl+H": () => this.sidePanel.open("FindAndReplace", {}),
365367
"Ctrl+F": () => this.sidePanel.open("FindAndReplace", {}),
366368
"Ctrl+Shift+E": () => this.setHorizontalAlign("center"),
@@ -409,6 +411,12 @@ export class Grid extends Component<Props, SpreadsheetChildEnv> {
409411
"Shift+PageUp": () => {
410412
this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET");
411413
},
414+
"Shift+F11": () => {
415+
insertSheet.execute?.(this.env);
416+
},
417+
"Alt+T": () => {
418+
insertTable.execute?.(this.env);
419+
},
412420
PageDown: () => this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),
413421
PageUp: () => this.env.model.dispatch("SHIFT_VIEWPORT_UP"),
414422
"Ctrl+K": () => INSERT_LINK(this.env),

tests/grid/grid_component.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ describe("Grid component", () => {
942942
expect(model.getters.getActiveSheetId()).toBe("third");
943943
});
944944

945+
// test("Pressing Shift+F11 insert a new sheet", () => {
946+
// });
947+
945948
test("pressing Ctrl+K opens the link editor", async () => {
946949
await keyDown({ key: "k", ctrlKey: true });
947950
expect(fixture.querySelector(".o-link-editor")).not.toBeNull();

0 commit comments

Comments
 (0)