-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathDelete.ts
More file actions
53 lines (46 loc) · 1.39 KB
/
Delete.ts
File metadata and controls
53 lines (46 loc) · 1.39 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../typings/Types";
import { runOnTargetsForEachEditor } from "../util/targetUtils";
import displayPendingEditDecorations from "../util/editDisplayUtils";
import { flatten } from "lodash";
import { performEditsAndUpdateSelections } from "../util/updateSelections";
export default class Delete implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "outside" }];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
async run(
[targets]: [TypedSelection[]],
{ showDecorations = true } = {}
): Promise<ActionReturnValue> {
if (showDecorations) {
await displayPendingEditDecorations(
targets,
this.graph.editStyles.pendingDelete
);
}
const thatMark = flatten(
await runOnTargetsForEachEditor(targets, async (editor, targets) => {
const edits = targets.map((target) => ({
range: target.selection.selection,
text: "",
}));
const [updatedSelections] = await performEditsAndUpdateSelections(
editor,
edits,
[targets.map((target) => target.selection.selection)]
);
return updatedSelections.map((selection) => ({
editor,
selection,
}));
})
);
return { thatMark };
}
}