Skip to content

Commit 0d0873e

Browse files
authored
Merge pull request #239747 from microsoft/osortega/contribution-ai-search-title
Adding command contributions to AI search title
2 parents 8c2d7c9 + d3cb513 commit 0d0873e

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/vs/workbench/contrib/search/browser/media/searchview.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@
204204
font-weight: 500;
205205
}
206206

207+
.search-view .textsearchresult .actionBarContainer {
208+
flex: 1 0 auto;
209+
text-align: right;
210+
}
211+
207212
.search-view .textsearchresult .monaco-icon-label .codicon {
208213
position: relative;
209214
font-size: 12px;

src/vs/workbench/contrib/search/browser/searchActionsRemoveReplace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ registerAction2(class RemoveAction extends Action2 {
7676
{
7777
id: MenuId.SearchActionMenu,
7878
group: 'inline',
79+
when: ContextKeyExpr.or(Constants.SearchContext.FileFocusKey, Constants.SearchContext.MatchFocusKey, Constants.SearchContext.FolderFocusKey),
7980
order: 2,
8081
},
8182
]

src/vs/workbench/contrib/search/browser/searchResultsView.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface IFolderMatchTemplate {
4747
interface ITextSearchResultTemplate {
4848
label: IResourceLabel;
4949
disposables: DisposableStore;
50+
actions: MenuWorkbenchToolBar;
51+
contextKeyService: IContextKeyService;
5052
}
5153

5254
interface IFileMatchTemplate {
@@ -102,7 +104,9 @@ export class TextSearchResultRenderer extends Disposable implements ICompressibl
102104

103105
constructor(
104106
private labels: ResourceLabels,
105-
@IWorkspaceContextService protected contextService: IWorkspaceContextService
107+
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
108+
@IInstantiationService private readonly instantiationService: IInstantiationService,
109+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
106110
) {
107111
super();
108112
}
@@ -114,12 +118,31 @@ export class TextSearchResultRenderer extends Disposable implements ICompressibl
114118
const textSearchResultElement = DOM.append(container, DOM.$('.textsearchresult'));
115119
const label = this.labels.create(textSearchResultElement, { supportDescriptionHighlights: true, supportHighlights: true, supportIcons: true });
116120
disposables.add(label);
117-
return { label, disposables };
121+
122+
const actionBarContainer = DOM.append(textSearchResultElement, DOM.$('.actionBarContainer'));
123+
const contextKeyServiceMain = disposables.add(this.contextKeyService.createScoped(container));
124+
125+
const instantiationService = disposables.add(this.instantiationService.createChild(new ServiceCollection([IContextKeyService, contextKeyServiceMain])));
126+
const actions = disposables.add(instantiationService.createInstance(MenuWorkbenchToolBar, actionBarContainer, MenuId.SearchActionMenu, {
127+
menuOptions: {
128+
shouldForwardArgs: true
129+
},
130+
highlightToggledItems: true,
131+
hiddenItemStrategy: HiddenItemStrategy.Ignore,
132+
toolbarOptions: {
133+
primaryGroup: (g: string) => /^inline/.test(g),
134+
},
135+
}));
136+
return { label, disposables, actions, contextKeyService: contextKeyServiceMain };
118137
}
119138

120139
async renderElement(node: ITreeNode<ITextSearchHeading, any>, index: number, templateData: IFolderMatchTemplate, height: number | undefined): Promise<void> {
121140
if (isPlainTextSearchHeading(node.element)) {
122141
templateData.label.setLabel(nls.localize('searchFolderMatch.plainText.label', "Text Results"));
142+
SearchContext.AIResultsTitle.bindTo(templateData.contextKeyService).set(false);
143+
SearchContext.MatchFocusKey.bindTo(templateData.contextKeyService).set(false);
144+
SearchContext.FileFocusKey.bindTo(templateData.contextKeyService).set(false);
145+
SearchContext.FolderFocusKey.bindTo(templateData.contextKeyService).set(false);
123146
} else {
124147
const aiName = await node.element.parent().searchModel.getAITextResultProviderName();
125148
const localizedLabel = nls.localize({
@@ -129,6 +152,11 @@ export class TextSearchResultRenderer extends Disposable implements ICompressibl
129152

130153
// todo: make icon extension-contributed.
131154
templateData.label.setLabel(`$(${Codicon.copilot.id}) ${localizedLabel}`);
155+
156+
SearchContext.AIResultsTitle.bindTo(templateData.contextKeyService).set(true);
157+
SearchContext.MatchFocusKey.bindTo(templateData.contextKeyService).set(false);
158+
SearchContext.FileFocusKey.bindTo(templateData.contextKeyService).set(false);
159+
SearchContext.FolderFocusKey.bindTo(templateData.contextKeyService).set(false);
132160
}
133161
}
134162

@@ -188,6 +216,7 @@ export class FolderMatchRenderer extends Disposable implements ICompressibleTree
188216
disposables.add(elementDisposables);
189217

190218
const contextKeyServiceMain = disposables.add(this.contextKeyService.createScoped(container));
219+
SearchContext.AIResultsTitle.bindTo(contextKeyServiceMain).set(false);
191220
SearchContext.MatchFocusKey.bindTo(contextKeyServiceMain).set(false);
192221
SearchContext.FileFocusKey.bindTo(contextKeyServiceMain).set(false);
193222
SearchContext.FolderFocusKey.bindTo(contextKeyServiceMain).set(true);
@@ -288,6 +317,7 @@ export class FileMatchRenderer extends Disposable implements ICompressibleTreeRe
288317
const actionBarContainer = DOM.append(fileMatchElement, DOM.$('.actionBarContainer'));
289318

290319
const contextKeyServiceMain = disposables.add(this.contextKeyService.createScoped(container));
320+
SearchContext.AIResultsTitle.bindTo(contextKeyServiceMain).set(false);
291321
SearchContext.MatchFocusKey.bindTo(contextKeyServiceMain).set(false);
292322
SearchContext.FileFocusKey.bindTo(contextKeyServiceMain).set(true);
293323
SearchContext.FolderFocusKey.bindTo(contextKeyServiceMain).set(false);
@@ -380,6 +410,7 @@ export class MatchRenderer extends Disposable implements ICompressibleTreeRender
380410
const disposables = new DisposableStore();
381411

382412
const contextKeyServiceMain = disposables.add(this.contextKeyService.createScoped(container));
413+
SearchContext.AIResultsTitle.bindTo(contextKeyServiceMain).set(false);
383414
SearchContext.MatchFocusKey.bindTo(contextKeyServiceMain).set(true);
384415
SearchContext.FileFocusKey.bindTo(contextKeyServiceMain).set(false);
385416
SearchContext.FolderFocusKey.bindTo(contextKeyServiceMain).set(false);

src/vs/workbench/contrib/search/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ export const SearchContext = {
7979
ViewHasSomeCollapsibleKey: new RawContextKey<boolean>('viewHasSomeCollapsibleResult', false),
8080
InTreeViewKey: new RawContextKey<boolean>('inTreeView', false),
8181
hasAIResultProvider: new RawContextKey<boolean>('hasAIResultProviderKey', false),
82+
AIResultsTitle: new RawContextKey<boolean>('aiResultsTitle', false),
8283
};

src/vs/workbench/services/actions/common/menusExtensionPoint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ const apiMenus: IAPIMenu[] = [
438438
id: MenuId.DiffEditorSelectionToolbar,
439439
description: localize('menus.diffEditorGutterToolBarMenus', "The gutter toolbar in the diff editor"),
440440
proposed: 'contribDiffEditorGutterToolBarMenus'
441+
},
442+
{
443+
key: 'searchPanel/feedback',
444+
id: MenuId.SearchActionMenu,
445+
description: localize('searchPanel.feedback', "The feedback menu rendered as buttons next to the AI search title"),
441446
}
442447
];
443448

0 commit comments

Comments
 (0)