diff --git a/README.md b/README.md index 435387e..2c95cf1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index dd190c0..920d7fc 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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": [ diff --git a/src/extension.ts b/src/extension.ts index 526494c..c9c3ddb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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); diff --git a/src/treeProvider.ts b/src/treeProvider.ts index e46855e..8316a0f 100644 --- a/src/treeProvider.ts +++ b/src/treeProvider.ts @@ -1100,6 +1100,16 @@ export class GitTreeCompareProvider implements TreeDataProvider, 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()); }