-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathSort.ts
More file actions
38 lines (31 loc) · 860 Bytes
/
Sort.ts
File metadata and controls
38 lines (31 loc) · 860 Bytes
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
import {
Action,
ActionReturnValue,
ActionPreferences,
Graph,
TypedSelection,
} from "../typings/Types";
export class Sort implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
protected sortTexts(texts: string[]) {
return texts.sort();
}
async run(targets: TypedSelection[][]): Promise<ActionReturnValue> {
const { returnValue: unsortedTexts } = await this.graph.actions.getText.run(
targets,
{
showDecorations: false,
}
);
const sortedTexts = this.sortTexts(unsortedTexts);
return this.graph.actions.replace.run(targets, sortedTexts);
}
}
export class Reverse extends Sort {
protected sortTexts(texts: string[]) {
return texts.reverse();
}
}