-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathCutCopyPaste.ts
More file actions
67 lines (57 loc) · 1.89 KB
/
CutCopyPaste.ts
File metadata and controls
67 lines (57 loc) · 1.89 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../typings/Types";
import { performInsideOutsideAdjustment } from "../util/performInsideOutsideAdjustment";
import CommandAction from "./CommandAction";
import displayPendingEditDecorations from "../util/editDisplayUtils";
import { getOutsideOverflow } from "../util/targetUtils";
import { zip } from "lodash";
export class Cut implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: null }];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
async run([targets]: [TypedSelection[]]): Promise<ActionReturnValue> {
const insideTargets = targets.map((target) =>
performInsideOutsideAdjustment(target, "inside")
);
const outsideTargets = targets.map((target) =>
performInsideOutsideAdjustment(target, "outside")
);
const outsideTargetDecorations = zip(insideTargets, outsideTargets).flatMap(
([inside, outside]) => getOutsideOverflow(inside!, outside!)
);
const options = { showDecorations: false };
await Promise.all([
displayPendingEditDecorations(
insideTargets,
this.graph.editStyles.referenced
),
displayPendingEditDecorations(
outsideTargetDecorations,
this.graph.editStyles.pendingDelete
),
]);
await this.graph.actions.copyToClipboard.run([insideTargets], options);
const { thatMark } = await this.graph.actions.remove.run(
[outsideTargets],
options
);
return { thatMark };
}
}
const OPTIONS = { ensureSingleEditor: true };
export class Copy extends CommandAction {
constructor(graph: Graph) {
super(graph, "editor.action.clipboardCopyAction", OPTIONS);
}
}
export class Paste extends CommandAction {
constructor(graph: Graph) {
super(graph, "editor.action.clipboardPasteAction", OPTIONS);
}
}