Skip to content

Commit

Permalink
Merge pull request mauricedb#13 from mnelsonwhite/feature/select-inst…
Browse files Browse the repository at this point in the history
…ruction

Sweet, I often use something like the command below but this is more flexible.
```
{
  "type": "command",
  "command": "editor.action.smartSelect.expand",
  "repeat": 3
},
```

Thanks
  • Loading branch information
mauricedb authored Nov 3, 2020
2 parents e05de16 + 3620c2a commit 6579156
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 6579156

Please sign in to comment.