Skip to content

Commit

Permalink
Add select instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
mnelsonwhite committed Nov 3, 2020
1 parent e05de16 commit 3620c2a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Example:

### GoTo

Go to a spefic position in the currently open file. The positions are 1 based so they match up with what Visual Studio Code displays. Both the line and column default to 1 if not specified.
Go to a specific position in the currently open file. The positions are 1 based so they match up with what Visual Studio Code displays. Both the line and column default to 1 if not specified.

Example:

Expand All @@ -87,6 +87,20 @@ Example:
}
```

### GoTo

Select from the current position to a specific position in the currently open file. The positions are 1 based so they match up with what Visual Studio Code displays. Both the line and column default to 1 if not specified.

Example:

```JSON
{
"type": "select",
"line": 75,
"column": 21
}
```

### Command

Executes one of the standard Visual Studio Code commands. The command should be one of the standard Visual Studio Code command names. See the Keyboard shortcuts for the known commands. When the command requires additional parameters an **args** array or primitive types can be passed along. Add an optional `repeat` settings if a command needs to be execured multiple times.
Expand Down
18 changes: 18 additions & 0 deletions src/instruction-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TypeText,
OpenFile,
GoTo,
Select,
CreateFile,
Wait,
TypeTextFromFile,
Expand Down Expand Up @@ -138,6 +139,23 @@ export const goto = async (instruction: GoTo): Promise<void> => {
await timeout(getDelay());
};

export const select = async (instruction: Select): Promise<void> => {
const { line = 1, column = 1 } = instruction;
const editor = window.activeTextEditor;
if (!editor) {
return;
}

const end = new Position(line - 1, column - 1);
editor.selection = new Selection(editor.selection.start, end);
editor.revealRange(
editor.selection,
TextEditorRevealType.InCenterIfOutsideViewport
);

await timeout(getDelay());
};

export const wait = (instruction: Wait): Promise<void> => {
return new Promise(async (resolve, reject) => {
if (instruction.save) {
Expand Down
2 changes: 2 additions & 0 deletions src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type CreateFile = { type: "createFile"; path: string };

export type GoTo = { type: "goto"; line: number; column: number };

export type Select = { type: "select"; line: number; column: number };

export type Instruction = (
| Command
| CreateFile
Expand Down

0 comments on commit 3620c2a

Please sign in to comment.