Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ export type ActionType =
| "cut"
| "delete"
| "extractVariable"
| "findInFiles"
| "fold"
| "getText"
| "indentLines"
| "insertLineAfter"
| "insertLineBefore"
Expand Down
28 changes: 28 additions & 0 deletions src/actions/Find.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
Action,
ActionReturnValue,
ActionPreferences,
Graph,
TypedSelection,
} from "../Types";
import { commands } from "vscode";
import { ensureSingleTarget } from "../targetUtils";

export class FindInFiles implements Action {
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
}

async run([targets]: [TypedSelection[]]): Promise<ActionReturnValue> {
ensureSingleTarget(targets);

const { returnValue: query, thatMark } =
await this.graph.actions.getText.run([targets]);

await commands.executeCommand("workbench.action.findInFiles", { query });

return { returnValue: null, thatMark };
}
}
40 changes: 40 additions & 0 deletions src/actions/GetText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../Types";
import displayPendingEditDecorations from "../editDisplayUtils";

export default class GetText implements Action {
Comment thread
AndreasArvidsson marked this conversation as resolved.
targetPreferences: ActionPreferences[] = [{ insideOutsideType: "inside" }];

constructor(private graph: Graph) {
this.run = this.run.bind(this);
}

async run(
[targets]: [TypedSelection[]],
showDecorations = true
): Promise<ActionReturnValue> {
if (showDecorations) {
await displayPendingEditDecorations(
targets,
this.graph.editStyles.referenced,
this.graph.editStyles.referencedLine
);
}

const text = targets
.map((target) =>
target.selection.editor.document.getText(target.selection.selection)
)
.join("\n");

return {
returnValue: text,
thatMark: targets.map((target) => target.selection),
};
}
}
20 changes: 4 additions & 16 deletions src/actions/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Graph,
TypedSelection,
} from "../Types";
import displayPendingEditDecorations from "../editDisplayUtils";
import { env } from "vscode";

export default class Copy implements Action {
Expand All @@ -16,23 +15,12 @@ export default class Copy implements Action {
}

async run([targets]: [TypedSelection[]]): Promise<ActionReturnValue> {
await displayPendingEditDecorations(
const { returnValue, thatMark } = await this.graph.actions.getText.run([
targets,
this.graph.editStyles.referenced,
this.graph.editStyles.referencedLine
);
]);

await env.clipboard.writeText(
targets
.map((target) =>
target.selection.editor.document.getText(target.selection.selection)
)
.join("\n")
);
await env.clipboard.writeText(returnValue);

return {
returnValue: null,
thatMark: targets.map((target) => target.selection),
};
return { returnValue: null, thatMark };
}
}
4 changes: 4 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { IndentLines, OutdentLines } from "./Indent";
import { CommentLines } from "./Comment";
import Paste from "./Paste";
import { Bring, Move, Swap } from "./BringMoveSwap";
import GetText from "./GetText";
import { FindInFiles } from "./Find";

class Actions implements ActionRecord {
constructor(private graph: Graph) {}
Expand All @@ -31,7 +33,9 @@ class Actions implements ActionRecord {
cut = new Cut(this.graph);
delete = new Delete(this.graph);
extractVariable = new ExtractVariable(this.graph);
findInFiles = new FindInFiles(this.graph);
fold = new Fold(this.graph);
getText = new GetText(this.graph);
indentLines = new IndentLines(this.graph);
insertLineBefore = new InsertLineBefore(this.graph);
insertLineAfter = new InsertLineAfter(this.graph);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/setSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ActionPreferences,
ActionReturnValue,
TypedSelection,
Graph
Graph,
} from "../Types";
import { ensureSingleEditor } from "../targetUtils";
import { Selection } from "vscode";
Expand Down Expand Up @@ -47,5 +47,5 @@ export class SetSelectionAfter extends SetSelection {
target.selection.selection.end,
target.selection.selection.end
);
1 }
}
}