diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index 1f89c13f399ce12ea6d9cf46c1d2453e32788213..eebefbd67484009bbc5d7a464159cf478e1cb4b0 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -659,7 +659,7 @@ export interface SelectionKeyboardEvent extends KeyboardEvent { preserveFocus?: boolean; } -export function getSelectionKeyboardEvent(typeArg: string, preserveFocus?: boolean): SelectionKeyboardEvent { +export function getSelectionKeyboardEvent(typeArg = 'keydown', preserveFocus?: boolean): SelectionKeyboardEvent { const e = new KeyboardEvent(typeArg); (e).preserveFocus = preserveFocus; diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index f0a3c4dd3f6d5db7b28c2b6111d7ebdde5954fc8..6e4f3b063768a562be8df86d5a1c72fecec651a2 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -17,18 +17,17 @@ import * as nls from 'vs/nls'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { ICommandHandler } from 'vs/platform/commands/common/commands'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { IEditorOptions } from 'vs/platform/editor/common/editor'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; -import { ISearchConfiguration, ISearchHistoryService, VIEW_ID } from 'vs/workbench/services/search/common/search'; +import { getSelectionKeyboardEvent, WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; import { SearchView } from 'vs/workbench/contrib/search/browser/searchView'; import * as Constants from 'vs/workbench/contrib/search/common/constants'; import { IReplaceService } from 'vs/workbench/contrib/search/common/replace'; -import { FileMatch, FileMatchOrMatch, FolderMatch, Match, RenderableMatch, searchMatchComparer, SearchResult, BaseFolderMatch } from 'vs/workbench/contrib/search/common/searchModel'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { BaseFolderMatch, FileMatch, FileMatchOrMatch, FolderMatch, Match, RenderableMatch, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; +import { ISearchConfiguration, ISearchHistoryService, VIEW_ID } from 'vs/workbench/services/search/common/search'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; export function isSearchViewFocused(viewletService: IViewletService, panelService: IPanelService): boolean { @@ -470,7 +469,7 @@ export class RemoveAction extends AbstractSearchAndReplaceAction { if (nextFocusElement) { this.viewer.reveal(nextFocusElement); - this.viewer.setFocus([nextFocusElement], getKeyboardEventForEditorOpen()); + this.viewer.setFocus([nextFocusElement], getSelectionKeyboardEvent()); } this.element.parent().remove(this.element); @@ -507,7 +506,7 @@ export class ReplaceAllAction extends AbstractSearchAndReplaceAction { const nextFocusElement = this.getElementToFocusAfterRemoved(tree, this.fileMatch); return this.fileMatch.parent().replace(this.fileMatch).then(() => { if (nextFocusElement) { - tree.setFocus([nextFocusElement], getKeyboardEventForEditorOpen()); + tree.setFocus([nextFocusElement], getSelectionKeyboardEvent()); } tree.domFocus(); @@ -530,7 +529,7 @@ export class ReplaceAllInFolderAction extends AbstractSearchAndReplaceAction { const nextFocusElement = this.getElementToFocusAfterRemoved(this.viewer, this.folderMatch); return this.folderMatch.replaceAll().then(() => { if (nextFocusElement) { - this.viewer.setFocus([nextFocusElement], getKeyboardEventForEditorOpen()); + this.viewer.setFocus([nextFocusElement], getSelectionKeyboardEvent()); } this.viewer.domFocus(); }); @@ -555,7 +554,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction { return this.element.parent().replace(this.element).then(() => { const elementToFocus = this.getElementToFocusAfterReplace(); if (elementToFocus) { - this.viewer.setFocus([elementToFocus], getKeyboardEventForEditorOpen()); + this.viewer.setFocus([elementToFocus], getSelectionKeyboardEvent()); } return this.getElementToShowReplacePreview(elementToFocus); @@ -748,13 +747,3 @@ export const focusSearchListCommand: ICommandHandler = accessor => { searchView.moveFocusToResults(); }); }; - -export function getKeyboardEventForEditorOpen(options: IEditorOptions = {}): KeyboardEvent { - const fakeKeyboardEvent = new KeyboardEvent('keydown'); - if (options.preserveFocus) { - // fake double click - (fakeKeyboardEvent).detail = 2; - } - - return fakeKeyboardEvent; -} diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index 9c1db22ceade38a683d1c30835578af85bc76e9c..52e381f537b0be267d191a2202e03d72feb8f471 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -32,7 +32,7 @@ import { IContextMenuService, IContextViewService } from 'vs/platform/contextvie import { IConfirmation, IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { FileChangesEvent, FileChangeType, IFileService } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { TreeResourceNavigator2, WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; +import { TreeResourceNavigator2, WorkbenchObjectTree, getSelectionKeyboardEvent } from 'vs/platform/list/browser/listService'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IProgressService } from 'vs/platform/progress/common/progress'; import { IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ISearchHistoryService, ISearchHistoryValues, ITextQuery, SearchErrorCode, VIEW_ID } from 'vs/workbench/services/search/common/search'; @@ -48,7 +48,7 @@ import { IEditor } from 'vs/workbench/common/editor'; import { IPanel } from 'vs/workbench/common/panel'; import { IViewlet } from 'vs/workbench/common/viewlet'; import { ExcludePatternInputWidget, PatternInputWidget } from 'vs/workbench/contrib/search/browser/patternInputWidget'; -import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, getKeyboardEventForEditorOpen, RefreshAction } from 'vs/workbench/contrib/search/browser/searchActions'; +import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, RefreshAction } from 'vs/workbench/contrib/search/browser/searchActions'; import { FileMatchRenderer, FolderMatchRenderer, MatchRenderer, SearchAccessibilityProvider, SearchDelegate, SearchDND } from 'vs/workbench/contrib/search/browser/searchResultsView'; import { ISearchWidgetOptions, SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget'; import * as Constants from 'vs/workbench/contrib/search/common/constants'; @@ -699,7 +699,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { selectCurrentMatch(): void { const focused = this.tree.getFocus()[0]; - const fakeKeyboardEvent = getKeyboardEventForEditorOpen({ preserveFocus: false }); + const fakeKeyboardEvent = getSelectionKeyboardEvent(undefined, false); this.tree.setSelection([focused], fakeKeyboardEvent); } @@ -734,8 +734,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { // Reveal the newly selected element if (next) { - this.tree.setFocus([next]); - this.tree.setSelection([next]); + this.tree.setFocus([next], getSelectionKeyboardEvent(undefined, false)); this.tree.reveal(next); this.selectCurrentMatchEmitter.fire(undefined); } @@ -775,8 +774,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { // Reveal the newly selected element if (prev) { - this.tree.setFocus([prev]); - this.tree.setSelection([prev]); + this.tree.setFocus([prev], getSelectionKeyboardEvent(undefined, false)); this.tree.reveal(prev); this.selectCurrentMatchEmitter.fire(undefined); }