-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added actions sort and reverse (#162)
* Added actions sort and reverse * cleanup
- Loading branch information
1 parent
df20a98
commit 988244c
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Action, | ||
ActionReturnValue, | ||
ActionPreferences, | ||
Graph, | ||
TypedSelection, | ||
} from "../Types"; | ||
|
||
export class Sort implements Action { | ||
targetPreferences: 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.replaceWithText.run(targets, sortedTexts); | ||
} | ||
} | ||
|
||
export class Reverse extends Sort { | ||
protected sortTexts(texts: string[]) { | ||
return texts.reverse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters