-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathGetText.ts
More file actions
44 lines (39 loc) · 1.08 KB
/
GetText.ts
File metadata and controls
44 lines (39 loc) · 1.08 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
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../typings/Types";
import displayPendingEditDecorations from "../util/editDisplayUtils";
import { ensureSingleTarget } from "../util/targetUtils";
export default class GetText implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
async run(
[targets]: [TypedSelection[]],
{
showDecorations = true,
ensureSingleTarget: doEnsureSingleTarget = false,
} = {}
): Promise<ActionReturnValue> {
if (showDecorations) {
await displayPendingEditDecorations(
targets,
this.graph.editStyles.referenced
);
}
if (doEnsureSingleTarget) {
ensureSingleTarget(targets);
}
const returnValue = targets.map((target) =>
target.selection.editor.document.getText(target.selection.selection)
);
return {
returnValue,
thatMark: targets.map((target) => target.selection),
};
}
}