fix references widget

上级 a790f912
...@@ -1099,12 +1099,6 @@ class TreeNodeListMouseController<T, TFilterData, TRef> extends MouseController< ...@@ -1099,12 +1099,6 @@ class TreeNodeListMouseController<T, TFilterData, TRef> extends MouseController<
} }
const onTwistie = hasClass(e.browserEvent.target as HTMLElement, 'monaco-tl-twistie'); const onTwistie = hasClass(e.browserEvent.target as HTMLElement, 'monaco-tl-twistie');
// TODO@joao: fix folder expansion
if (e.browserEvent.detail !== 2 && !onTwistie) {
return super.onPointer(e);
}
let expandOnlyOnTwistieClick = false; let expandOnlyOnTwistieClick = false;
if (typeof this.tree.expandOnlyOnTwistieClick === 'function') { if (typeof this.tree.expandOnlyOnTwistieClick === 'function') {
......
...@@ -317,6 +317,8 @@ export class ReferenceWidget extends peekView.PeekViewWidget { ...@@ -317,6 +317,8 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
accessibilityProvider: new AccessibilityProvider(), accessibilityProvider: new AccessibilityProvider(),
keyboardNavigationLabelProvider: this._instantiationService.createInstance(StringRepresentationProvider), keyboardNavigationLabelProvider: this._instantiationService.createInstance(StringRepresentationProvider),
identityProvider: new IdentityProvider(), identityProvider: new IdentityProvider(),
openOnSingleClick: true,
openOnFocus: true,
overrideStyles: { overrideStyles: {
listBackground: peekView.peekViewResultsBackground listBackground: peekView.peekViewResultsBackground
} }
...@@ -372,21 +374,12 @@ export class ReferenceWidget extends peekView.PeekViewWidget { ...@@ -372,21 +374,12 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
this._onDidSelectReference.fire({ element, kind, source: 'tree' }); this._onDidSelectReference.fire({ element, kind, source: 'tree' });
} }
}; };
this._tree.onDidChangeFocus(e => {
onEvent(e.elements[0], 'show');
});
this._tree.onDidOpen(e => { this._tree.onDidOpen(e => {
if (e.browserEvent instanceof MouseEvent && (e.browserEvent.ctrlKey || e.browserEvent.metaKey || e.browserEvent.altKey)) { if (e.sideBySide) {
// modifier-click -> open to the side
onEvent(e.element, 'side'); onEvent(e.element, 'side');
} else if (e.browserEvent instanceof KeyboardEvent || (e.browserEvent instanceof MouseEvent && e.browserEvent.detail === 2) || (<GestureEvent>e.browserEvent).tapCount === 2) { } else if (e.editorOptions.pinned) {
// keybinding (list service command)
// OR double click
// OR double tap
// -> close widget and goto target
onEvent(e.element, 'goto'); onEvent(e.element, 'goto');
} else { } else {
// preview location
onEvent(e.element, 'show'); onEvent(e.element, 'show');
} }
}); });
......
...@@ -28,6 +28,7 @@ import { IKeyboardNavigationEventFilter, IAbstractTreeOptions, RenderIndentGuide ...@@ -28,6 +28,7 @@ import { IKeyboardNavigationEventFilter, IAbstractTreeOptions, RenderIndentGuide
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
export type ListWidget = List<any> | PagedList<any> | ObjectTree<any, any> | DataTree<any, any, any> | AsyncDataTree<any, any, any>; export type ListWidget = List<any> | PagedList<any> | ObjectTree<any, any> | DataTree<any, any, any> | AsyncDataTree<any, any, any>;
export type WorkbenchListWidget = WorkbenchList<any> | WorkbenchPagedList<any> | WorkbenchObjectTree<any, any> | WorkbenchCompressibleObjectTree<any, any> | WorkbenchDataTree<any, any, any> | WorkbenchAsyncDataTree<any, any, any> | WorkbenchCompressibleAsyncDataTree<any, any, any>;
export const IListService = createDecorator<IListService>('listService'); export const IListService = createDecorator<IListService>('listService');
...@@ -38,11 +39,11 @@ export interface IListService { ...@@ -38,11 +39,11 @@ export interface IListService {
/** /**
* Returns the currently focused list widget if any. * Returns the currently focused list widget if any.
*/ */
readonly lastFocusedList: ListWidget | undefined; readonly lastFocusedList: WorkbenchListWidget | undefined;
} }
interface IRegisteredList { interface IRegisteredList {
widget: ListWidget; widget: WorkbenchListWidget;
extraContextKeys?: (IContextKey<boolean>)[]; extraContextKeys?: (IContextKey<boolean>)[];
} }
...@@ -52,17 +53,17 @@ export class ListService implements IListService { ...@@ -52,17 +53,17 @@ export class ListService implements IListService {
private disposables = new DisposableStore(); private disposables = new DisposableStore();
private lists: IRegisteredList[] = []; private lists: IRegisteredList[] = [];
private _lastFocusedWidget: ListWidget | undefined = undefined; private _lastFocusedWidget: WorkbenchListWidget | undefined = undefined;
private _hasCreatedStyleController: boolean = false; private _hasCreatedStyleController: boolean = false;
get lastFocusedList(): ListWidget | undefined { get lastFocusedList(): WorkbenchListWidget | undefined {
return this._lastFocusedWidget; return this._lastFocusedWidget;
} }
constructor(@IThemeService private readonly _themeService: IThemeService) { constructor(@IThemeService private readonly _themeService: IThemeService) {
} }
register(widget: ListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable { register(widget: WorkbenchListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable {
if (!this._hasCreatedStyleController) { if (!this._hasCreatedStyleController) {
this._hasCreatedStyleController = true; this._hasCreatedStyleController = true;
// create a shared default tree style sheet for performance reasons // create a shared default tree style sheet for performance reasons
...@@ -477,7 +478,7 @@ abstract class ResourceNavigator<T> extends Disposable { ...@@ -477,7 +478,7 @@ abstract class ResourceNavigator<T> extends Disposable {
!!(<SelectionKeyboardEvent>browserEvent).preserveFocus : !!(<SelectionKeyboardEvent>browserEvent).preserveFocus :
true; true;
this.open(preserveFocus, false, false, browserEvent); this._open(preserveFocus, false, false, browserEvent);
} }
} }
...@@ -497,7 +498,7 @@ abstract class ResourceNavigator<T> extends Disposable { ...@@ -497,7 +498,7 @@ abstract class ResourceNavigator<T> extends Disposable {
if (this.openOnSingleClick || isDoubleClick || isKeyboardEvent) { if (this.openOnSingleClick || isDoubleClick || isKeyboardEvent) {
const sideBySide = browserEvent instanceof MouseEvent && (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey); const sideBySide = browserEvent instanceof MouseEvent && (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey);
this.open(preserveFocus, isDoubleClick || isMiddleClick, sideBySide, browserEvent); this._open(preserveFocus, isDoubleClick || isMiddleClick, sideBySide, browserEvent);
} }
} }
...@@ -507,10 +508,10 @@ abstract class ResourceNavigator<T> extends Disposable { ...@@ -507,10 +508,10 @@ abstract class ResourceNavigator<T> extends Disposable {
} }
const sideBySide = (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey); const sideBySide = (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey);
this.open(true, true, sideBySide, browserEvent); this._open(true, true, sideBySide, browserEvent);
} }
private open(preserveFocus: boolean, pinned: boolean, sideBySide: boolean, browserEvent?: UIEvent): void { private _open(preserveFocus: boolean, pinned: boolean, sideBySide: boolean, browserEvent?: UIEvent): void {
this._onDidOpen.fire({ this._onDidOpen.fire({
editorOptions: { editorOptions: {
preserveFocus, preserveFocus,
...@@ -522,6 +523,11 @@ abstract class ResourceNavigator<T> extends Disposable { ...@@ -522,6 +523,11 @@ abstract class ResourceNavigator<T> extends Disposable {
browserEvent browserEvent
}); });
} }
// hack for References Widget: pressing Enter on already selected tree element
open(browserEvent?: UIEvent): void {
this._open((browserEvent as any)?.preserveFocus || false, true, false, browserEvent);
}
} }
export class ListResourceNavigator<T> extends ResourceNavigator<number> { export class ListResourceNavigator<T> extends ResourceNavigator<number> {
...@@ -594,6 +600,10 @@ export class WorkbenchObjectTree<T extends NonNullable<any>, TFilterData = void> ...@@ -594,6 +600,10 @@ export class WorkbenchObjectTree<T extends NonNullable<any>, TFilterData = void>
this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
this.disposables.add(this.internals); this.disposables.add(this.internals);
} }
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
} }
export interface IWorkbenchCompressibleObjectTreeOptionsUpdate extends ICompressibleObjectTreeOptionsUpdate { export interface IWorkbenchCompressibleObjectTreeOptionsUpdate extends ICompressibleObjectTreeOptionsUpdate {
...@@ -638,6 +648,10 @@ export class WorkbenchCompressibleObjectTree<T extends NonNullable<any>, TFilter ...@@ -638,6 +648,10 @@ export class WorkbenchCompressibleObjectTree<T extends NonNullable<any>, TFilter
this.internals.updateStyleOverrides(options.overrideStyles); this.internals.updateStyleOverrides(options.overrideStyles);
} }
} }
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
} }
export interface IWorkbenchDataTreeOptionsUpdate extends IAbstractTreeOptionsUpdate { export interface IWorkbenchDataTreeOptionsUpdate extends IAbstractTreeOptionsUpdate {
...@@ -683,6 +697,10 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T ...@@ -683,6 +697,10 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T
this.internals.updateStyleOverrides(options.overrideStyles); this.internals.updateStyleOverrides(options.overrideStyles);
} }
} }
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
} }
export interface IWorkbenchAsyncDataTreeOptionsUpdate extends IAsyncDataTreeOptionsUpdate { export interface IWorkbenchAsyncDataTreeOptionsUpdate extends IAsyncDataTreeOptionsUpdate {
...@@ -728,6 +746,10 @@ export class WorkbenchAsyncDataTree<TInput, T, TFilterData = void> extends Async ...@@ -728,6 +746,10 @@ export class WorkbenchAsyncDataTree<TInput, T, TFilterData = void> extends Async
this.internals.updateStyleOverrides(options.overrideStyles); this.internals.updateStyleOverrides(options.overrideStyles);
} }
} }
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
} }
export interface IWorkbenchCompressibleAsyncDataTreeOptions<T, TFilterData> extends ICompressibleAsyncDataTreeOptions<T, TFilterData>, IResourceNavigatorOptions { export interface IWorkbenchCompressibleAsyncDataTreeOptions<T, TFilterData> extends ICompressibleAsyncDataTreeOptions<T, TFilterData>, IResourceNavigatorOptions {
...@@ -763,6 +785,10 @@ export class WorkbenchCompressibleAsyncDataTree<TInput, T, TFilterData = void> e ...@@ -763,6 +785,10 @@ export class WorkbenchCompressibleAsyncDataTree<TInput, T, TFilterData = void> e
this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
this.disposables.add(this.internals); this.disposables.add(this.internals);
} }
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
} }
function workbenchTreeDataPreamble<T, TFilterData, TOptions extends IAbstractTreeOptions<T, TFilterData> | IAsyncDataTreeOptions<T, TFilterData>>( function workbenchTreeDataPreamble<T, TFilterData, TOptions extends IAbstractTreeOptions<T, TFilterData> | IAsyncDataTreeOptions<T, TFilterData>>(
...@@ -935,6 +961,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> { ...@@ -935,6 +961,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
this.styler = overrideStyles ? attachListStyler(this.tree, this.themeService, overrideStyles) : Disposable.None; this.styler = overrideStyles ? attachListStyler(this.tree, this.themeService, overrideStyles) : Disposable.None;
} }
open(browserEvent?: UIEvent): void {
this.navigator.open(browserEvent);
}
dispose(): void { dispose(): void {
this.disposables = dispose(this.disposables); this.disposables = dispose(this.disposables);
dispose(this.styler); dispose(this.styler);
......
...@@ -506,23 +506,24 @@ function focusElement(accessor: ServicesAccessor, retainCurrentFocus: boolean): ...@@ -506,23 +506,24 @@ function focusElement(accessor: ServicesAccessor, retainCurrentFocus: boolean):
// Trees // Trees
else if (focused instanceof ObjectTree || focused instanceof DataTree || focused instanceof AsyncDataTree) { else if (focused instanceof ObjectTree || focused instanceof DataTree || focused instanceof AsyncDataTree) {
const list = focused; const tree = focused;
const focus = list.getFocus(); const focus = tree.getFocus();
if (focus.length > 0) { if (focus.length > 0) {
let toggleCollapsed = true; let toggleCollapsed = true;
if (list.expandOnlyOnTwistieClick === true) { if (tree.expandOnlyOnTwistieClick === true) {
toggleCollapsed = false; toggleCollapsed = false;
} else if (typeof list.expandOnlyOnTwistieClick !== 'boolean' && list.expandOnlyOnTwistieClick(focus[0])) { } else if (typeof tree.expandOnlyOnTwistieClick !== 'boolean' && tree.expandOnlyOnTwistieClick(focus[0])) {
toggleCollapsed = false; toggleCollapsed = false;
} }
if (toggleCollapsed) { if (toggleCollapsed) {
list.toggleCollapsed(focus[0]); tree.toggleCollapsed(focus[0]);
} }
} }
list.setSelection(focus, fakeKeyboardEvent); tree.setSelection(focus, fakeKeyboardEvent);
tree.open(fakeKeyboardEvent);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册