Skip to content

Commit

Permalink
Take search editor out of preview.
Browse files Browse the repository at this point in the history
Closes #23931. Closes #16488.
  • Loading branch information
Jackson Kearl committed Feb 22, 2020
1 parent 99d5733 commit 2402d70
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 62 deletions.
16 changes: 5 additions & 11 deletions src/vs/workbench/contrib/search/browser/search.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import { ExplorerViewPaneContainer } from 'vs/workbench/contrib/files/browser/ex
import { assertType, assertIsDefined } from 'vs/base/common/types';
import { SearchViewPaneContainer } from 'vs/workbench/contrib/search/browser/searchViewlet';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import product from 'vs/platform/product/common/product';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';

registerSingleton(ISearchWorkbenchService, SearchWorkbenchService, true);
Expand Down Expand Up @@ -775,21 +774,16 @@ configurationRegistry.registerConfiguration({
default: 300,
markdownDescription: nls.localize('search.searchOnTypeDebouncePeriod', "When `#search.searchOnType#` is enabled, controls the timeout in milliseconds between a character being typed and the search starting. Has no effect when `search.searchOnType` is disabled.")
},
'search.enableSearchEditorPreview': {
type: 'boolean',
default: product.quality !== 'stable',
description: nls.localize('search.enableSearchEditorPreview', "Experimental: When enabled, allows opening workspace search results in an editor.")
},
'search.searchEditorPreview.doubleClickBehaviour': {
'search.searchEditor.doubleClickBehaviour': {
type: 'string',
enum: ['selectWord', 'goToLocation', 'openLocationToSide'],
default: 'goToLocation',
enumDescriptions: [
nls.localize('search.searchEditorPreview.doubleClickBehaviour.selectWord', "Double clicking selects the word under the cursor."),
nls.localize('search.searchEditorPreview.doubleClickBehaviour.goToLocation', "Double clicking opens the result in the active editor group."),
nls.localize('search.searchEditorPreview.doubleClickBehaviour.openLocationToSide', "Double clicking opens the result in the editor group to the side, creating one if it does not yet exist."),
nls.localize('search.searchEditor.doubleClickBehaviour.selectWord', "Double clicking selects the word under the cursor."),
nls.localize('search.searchEditor.doubleClickBehaviour.goToLocation', "Double clicking opens the result in the active editor group."),
nls.localize('search.searchEditor.doubleClickBehaviour.openLocationToSide', "Double clicking opens the result in the editor group to the side, creating one if it does not yet exist."),
],
markdownDescription: nls.localize('search.searchEditorPreview.doubleClickBehaviour', "Configure effect of double clicking a result in a Search Editor.\n\n `#search.enableSearchEditorPreview#` must be enabled for this setting to have an effect.")
markdownDescription: nls.localize('search.searchEditor.doubleClickBehaviour', "Configure effect of double clicking a result in a search editor.")
},
'search.sortOrder': {
'type': 'string',
Expand Down
31 changes: 11 additions & 20 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,9 @@ export class SearchView extends ViewPane {

this.actions = [
this._register(this.instantiationService.createInstance(ClearSearchResultsAction, ClearSearchResultsAction.ID, ClearSearchResultsAction.LABEL)),
this._register(this.instantiationService.createInstance(OpenSearchEditorAction, OpenSearchEditorAction.ID, OpenSearchEditorAction.LABEL))
];

if (this.searchConfig.enableSearchEditorPreview) {
this.actions.push(
this._register(this.instantiationService.createInstance(OpenSearchEditorAction, OpenSearchEditorAction.ID, OpenSearchEditorAction.LABEL))
);
}

this.refreshAction = this._register(this.instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL));
this.cancelAction = this._register(this.instantiationService.createInstance(CancelSearchAction, CancelSearchAction.ID, CancelSearchAction.LABEL));
this.toggleCollapseAction = this._register(this.instantiationService.createInstance(ToggleCollapseAndExpandAction, ToggleCollapseAndExpandAction.ID, ToggleCollapseAndExpandAction.LABEL, collapseDeepestExpandedLevelAction, expandAllAction));
Expand Down Expand Up @@ -1561,23 +1556,19 @@ export class SearchView extends ViewPane {
resultMsg += nls.localize('useIgnoresAndExcludesDisabled', " - exclude settings and ignore files are disabled");
}

if (this.searchConfig.enableSearchEditorPreview) {
dom.append(messageEl, $('span', undefined, resultMsg + ' - '));
const span = dom.append(messageEl, $('span'));
const openInEditorLink = dom.append(span, $('a.pointer.prominent', undefined, nls.localize('openInEditor.message', "Open in editor")));
dom.append(messageEl, $('span', undefined, resultMsg + ' - '));
const span = dom.append(messageEl, $('span'));
const openInEditorLink = dom.append(span, $('a.pointer.prominent', undefined, nls.localize('openInEditor.message', "Open in editor")));

openInEditorLink.title = appendKeyBindingLabel(
nls.localize('openInEditor.tooltip', "Copy current search results to an editor"),
this.keybindingService.lookupKeybinding(Constants.OpenInEditorCommandId), this.keybindingService);
openInEditorLink.title = appendKeyBindingLabel(
nls.localize('openInEditor.tooltip', "Copy current search results to an editor"),
this.keybindingService.lookupKeybinding(Constants.OpenInEditorCommandId), this.keybindingService);

this.messageDisposables.push(dom.addDisposableListener(openInEditorLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);
this.instantiationService.invokeFunction(createEditorFromSearchResult, this.searchResult, this.searchIncludePattern.getValue(), this.searchExcludePattern.getValue());
}));
this.messageDisposables.push(dom.addDisposableListener(openInEditorLink, dom.EventType.CLICK, (e: MouseEvent) => {
dom.EventHelper.stop(e, false);
this.instantiationService.invokeFunction(createEditorFromSearchResult, this.searchResult, this.searchIncludePattern.getValue(), this.searchExcludePattern.getValue());
}));

} else {
dom.append(messageEl, $('span', undefined, resultMsg));
}
this.reLayout();
} else if (!msgWasHidden) {
dom.hide(this.messagesElement);
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/contrib/searchEditor/browser/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const ToggleSearchEditorWholeWordCommandId = 'toggleSearchEditorWholeWord
export const ToggleSearchEditorRegexCommandId = 'toggleSearchEditorRegex';
export const ToggleSearchEditorContextLinesCommandId = 'toggleSearchEditorContextLines';

export const EnableSearchEditorPreview = new RawContextKey<boolean>('previewSearchEditor', false);
export const InSearchEditor = new RawContextKey<boolean>('inSearchEditor', false);

export const SearchEditorScheme = 'search-editor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { URI } from 'vs/base/common/uri';
import { ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
import { localize } from 'vs/nls';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand All @@ -29,7 +28,8 @@ import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEd
import { OpenResultsInEditorAction, OpenSearchEditorAction, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
import { getOrMakeSearchEditorInput, SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ISearchConfigurationProperties } from 'vs/workbench/services/search/common/search';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';

//#region Editor Descriptior
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
Expand All @@ -51,16 +51,7 @@ class SearchEditorContribution implements IWorkbenchContribution {
@IInstantiationService protected readonly instantiationService: IInstantiationService,
@ITelemetryService protected readonly telemetryService: ITelemetryService,
@IContextKeyService protected readonly contextKeyService: IContextKeyService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
const enableSearchEditorPreview = SearchEditorConstants.EnableSearchEditorPreview.bindTo(this.contextKeyService);

enableSearchEditorPreview.set(this.searchConfig.enableSearchEditorPreview);
configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('search.previewSearchEditor')) {
enableSearchEditorPreview.set(this.searchConfig.enableSearchEditorPreview);
}
});

this.editorService.overrideOpenEditor((editor, options, group) => {
const resource = editor.resource;
Expand All @@ -83,10 +74,6 @@ class SearchEditorContribution implements IWorkbenchContribution {
return { override: Promise.resolve(opened) };
});
}

private get searchConfig(): ISearchConfigurationProperties {
return this.configurationService.getValue<ISearchConfigurationProperties>('search');
}
}

const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
Expand Down Expand Up @@ -167,12 +154,10 @@ const category = localize('search', "Search Editor");
registry.registerWorkbenchAction(
SyncActionDescriptor.create(OpenResultsInEditorAction, OpenResultsInEditorAction.ID, OpenResultsInEditorAction.LABEL,
{ mac: { primary: KeyMod.CtrlCmd | KeyCode.Enter } },
ContextKeyExpr.and(SearchConstants.HasSearchResults, SearchConstants.SearchViewFocusedKey, SearchEditorConstants.EnableSearchEditorPreview)),
'Search Editor: Open Results in Editor', category,
ContextKeyExpr.and(SearchEditorConstants.EnableSearchEditorPreview));
ContextKeyExpr.and(SearchConstants.HasSearchResults, SearchConstants.SearchViewFocusedKey)),
'Search Editor: Open Results in Editor', category);

registry.registerWorkbenchAction(
SyncActionDescriptor.create(OpenSearchEditorAction, OpenSearchEditorAction.ID, OpenSearchEditorAction.LABEL),
'Search Editor: Open New Search Editor', category,
ContextKeyExpr.and(SearchEditorConstants.EnableSearchEditorPreview));
'Search Editor: Open New Search Editor', category);
//#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class SearchEditor extends BaseTextEditor {
this.searchResultEditor = super.getControl() as CodeEditorWidget;
this.searchResultEditor.onMouseUp(e => {
if (e.event.detail === 2) {
const behaviour = this.configurationService.getValue<ISearchConfigurationProperties>('search').searchEditorPreview.doubleClickBehaviour;
const behaviour = this.configurationService.getValue<ISearchConfigurationProperties>('search').searchEditor.doubleClickBehaviour;
const position = e.target.position;
if (position && behaviour !== 'selectWord') {
const line = this.searchResultEditor.getModel()?.getLineContent(position.lineNumber) ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class OpenSearchEditorAction extends Action {
static readonly LABEL = localize('search.openNewEditor', "Open New Search Editor");

constructor(id: string, label: string,
@IConfigurationService private configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super(id, label, 'codicon-new-file');
Expand All @@ -76,9 +75,7 @@ export class OpenSearchEditorAction extends Action {
}

async run() {
if (this.configurationService.getValue<ISearchConfigurationProperties>('search').enableSearchEditorPreview) {
await this.instantiationService.invokeFunction(openNewSearchEditor);
}
await this.instantiationService.invokeFunction(openNewSearchEditor);
}
}

Expand All @@ -89,7 +86,6 @@ export class OpenResultsInEditorAction extends Action {

constructor(id: string, label: string,
@IViewsService private viewsService: IViewsService,
@IConfigurationService private configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super(id, label, 'codicon-go-to-file');
Expand All @@ -106,7 +102,7 @@ export class OpenResultsInEditorAction extends Action {

async run() {
const searchView = getSearchView(this.viewsService);
if (searchView && this.configurationService.getValue<ISearchConfigurationProperties>('search').enableSearchEditorPreview) {
if (searchView) {
await this.instantiationService.invokeFunction(createEditorFromSearchResult, searchView.searchResult, searchView.searchIncludePattern.getValue(), searchView.searchExcludePattern.getValue());
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/vs/workbench/services/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ export interface ISearchConfigurationProperties {
collapseResults: 'auto' | 'alwaysCollapse' | 'alwaysExpand';
searchOnType: boolean;
searchOnTypeDebouncePeriod: number;
enableSearchEditorPreview: boolean;
searchEditorPreview: { doubleClickBehaviour: 'selectWord' | 'goToLocation' | 'openLocationToSide' };
searchEditorPreviewForceAbsolutePaths: boolean;
searchEditor: { doubleClickBehaviour: 'selectWord' | 'goToLocation' | 'openLocationToSide' };
sortOrder: SearchSortOrder;
}

Expand Down

0 comments on commit 2402d70

Please sign in to comment.