Skip to content

Commit

Permalink
add simple way to search within changed files (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich authored Nov 15, 2024
1 parent 7e2e89d commit 838903f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ In bigger projects with many files it also provides **context**, it gives you a

- Log output of all git commands run

- Search within changed files

## Location

By default, the tree view is located in its own container accessible from the activity bar on the left. However, it can be freely moved to any other location like Source Control or Explorer by dragging and dropping.
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@
"title": "View as Tree",
"icon": "$(list-tree)",
"category": "Git Tree Compare"
},
{
"command": "gitTreeCompare.searchChanges",
"title": "Search Changes",
"icon": "$(search)",
"category": "Git Tree Compare"
}
],
"menus": {
Expand Down Expand Up @@ -220,6 +226,11 @@
"command": "gitTreeCompare.viewAsTree",
"when": "view == gitTreeCompare && gitTreeCompare.viewAsList",
"group": "navigation@1"
},
{
"command": "gitTreeCompare.searchChanges",
"when": "view == gitTreeCompare",
"group": "2_files"
}
],
"view/item/context": [
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export function activate(context: ExtensionContext) {
commands.registerCommand(NAMESPACE + '.viewAsTree', () => {
runAfterInit(() => provider!.viewAsTree(true));
});
commands.registerCommand(NAMESPACE + '.searchChanges', () => {
runAfterInit(() => provider!.searchChanges());
});

createGit(gitApi, outputChannel).then(async git => {
const onOutput = (str: string) => outputChannel.append(str);
Expand Down
10 changes: 10 additions & 0 deletions src/treeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,16 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
this._onDidChangeTreeData.fire();
}

async searchChanges() {
const uris = [...this.iterFiles()].map(file => Uri.file(file.dstAbsPath));
const relativePaths = uris.map(uri => path.relative(this.repoRoot, uri.fsPath));
await commands.executeCommand('workbench.action.findInFiles', {
query: '',
filesToInclude: relativePaths.join(','),
triggerSearch: true
});
}

dispose(): void {
this.disposables.forEach(d => d.dispose());
}
Expand Down

0 comments on commit 838903f

Please sign in to comment.