All files / src/packlets/editor-core/slices editor-command-slice.ts

91.66% Statements 11/12
50% Branches 1/2
100% Functions 5/5
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                  1x     51x       3x 3x   3x 3x 3x 5x 5x 5x   3x      
import { Slice } from "../slice";
import type { EditorContext } from "../editor-context";
import { SelectionSlice } from "./selection-slice";
import { ProjectSlice } from "./project-slice";
import { HistorySlice } from "./history-slice";
import type { Entity } from "../../entity-manager";
import { DeleteUserAction } from "../user-actions";
 
export class EditorCommandSlice extends Slice {
  static readonly sliceKey = "editorCommand";
 
  constructor(ctx: EditorContext) {
    super(ctx);
  }
 
  deleteSelection(): void {
    const selection = this.ctx.get(SelectionSlice).$selection.get();
    Iif (selection.size === 0) return;
 
    const entityManager = this.ctx.get(ProjectSlice).entityManager;
    const entityIds = Array.from(selection);
    const entities = entityIds
      .map((id) => entityManager.get(id))
      .filter((e): e is Entity => e !== undefined)
      .map((e) => structuredClone(e));
 
    this.ctx.get(HistorySlice).applyAction(new DeleteUserAction(this.ctx, entityIds, entities));
  }
}