Skip to content

Commit f86fd68

Browse files
committed
fix references widget
1 parent a790f91 commit f86fd68

4 files changed

Lines changed: 50 additions & 32 deletions

File tree

src/vs/base/browser/ui/tree/abstractTree.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,6 @@ class TreeNodeListMouseController<T, TFilterData, TRef> extends MouseController<
10991099
}
11001100

11011101
const onTwistie = hasClass(e.browserEvent.target as HTMLElement, 'monaco-tl-twistie');
1102-
1103-
// TODO@joao: fix folder expansion
1104-
if (e.browserEvent.detail !== 2 && !onTwistie) {
1105-
return super.onPointer(e);
1106-
}
1107-
11081102
let expandOnlyOnTwistieClick = false;
11091103

11101104
if (typeof this.tree.expandOnlyOnTwistieClick === 'function') {

src/vs/editor/contrib/gotoSymbol/peek/referencesWidget.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
317317
accessibilityProvider: new AccessibilityProvider(),
318318
keyboardNavigationLabelProvider: this._instantiationService.createInstance(StringRepresentationProvider),
319319
identityProvider: new IdentityProvider(),
320+
openOnSingleClick: true,
321+
openOnFocus: true,
320322
overrideStyles: {
321323
listBackground: peekView.peekViewResultsBackground
322324
}
@@ -372,21 +374,12 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
372374
this._onDidSelectReference.fire({ element, kind, source: 'tree' });
373375
}
374376
};
375-
this._tree.onDidChangeFocus(e => {
376-
onEvent(e.elements[0], 'show');
377-
});
378377
this._tree.onDidOpen(e => {
379-
if (e.browserEvent instanceof MouseEvent && (e.browserEvent.ctrlKey || e.browserEvent.metaKey || e.browserEvent.altKey)) {
380-
// modifier-click -> open to the side
378+
if (e.sideBySide) {
381379
onEvent(e.element, 'side');
382-
} else if (e.browserEvent instanceof KeyboardEvent || (e.browserEvent instanceof MouseEvent && e.browserEvent.detail === 2) || (<GestureEvent>e.browserEvent).tapCount === 2) {
383-
// keybinding (list service command)
384-
// OR double click
385-
// OR double tap
386-
// -> close widget and goto target
380+
} else if (e.editorOptions.pinned) {
387381
onEvent(e.element, 'goto');
388382
} else {
389-
// preview location
390383
onEvent(e.element, 'show');
391384
}
392385
});

src/vs/platform/list/browser/listService.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { IKeyboardNavigationEventFilter, IAbstractTreeOptions, RenderIndentGuide
2828
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
2929

3030
export type ListWidget = List<any> | PagedList<any> | ObjectTree<any, any> | DataTree<any, any, any> | AsyncDataTree<any, any, any>;
31+
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>;
3132

3233
export const IListService = createDecorator<IListService>('listService');
3334

@@ -38,11 +39,11 @@ export interface IListService {
3839
/**
3940
* Returns the currently focused list widget if any.
4041
*/
41-
readonly lastFocusedList: ListWidget | undefined;
42+
readonly lastFocusedList: WorkbenchListWidget | undefined;
4243
}
4344

4445
interface IRegisteredList {
45-
widget: ListWidget;
46+
widget: WorkbenchListWidget;
4647
extraContextKeys?: (IContextKey<boolean>)[];
4748
}
4849

@@ -52,17 +53,17 @@ export class ListService implements IListService {
5253

5354
private disposables = new DisposableStore();
5455
private lists: IRegisteredList[] = [];
55-
private _lastFocusedWidget: ListWidget | undefined = undefined;
56+
private _lastFocusedWidget: WorkbenchListWidget | undefined = undefined;
5657
private _hasCreatedStyleController: boolean = false;
5758

58-
get lastFocusedList(): ListWidget | undefined {
59+
get lastFocusedList(): WorkbenchListWidget | undefined {
5960
return this._lastFocusedWidget;
6061
}
6162

6263
constructor(@IThemeService private readonly _themeService: IThemeService) {
6364
}
6465

65-
register(widget: ListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable {
66+
register(widget: WorkbenchListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable {
6667
if (!this._hasCreatedStyleController) {
6768
this._hasCreatedStyleController = true;
6869
// create a shared default tree style sheet for performance reasons
@@ -477,7 +478,7 @@ abstract class ResourceNavigator<T> extends Disposable {
477478
!!(<SelectionKeyboardEvent>browserEvent).preserveFocus :
478479
true;
479480

480-
this.open(preserveFocus, false, false, browserEvent);
481+
this._open(preserveFocus, false, false, browserEvent);
481482
}
482483
}
483484

@@ -497,7 +498,7 @@ abstract class ResourceNavigator<T> extends Disposable {
497498

498499
if (this.openOnSingleClick || isDoubleClick || isKeyboardEvent) {
499500
const sideBySide = browserEvent instanceof MouseEvent && (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey);
500-
this.open(preserveFocus, isDoubleClick || isMiddleClick, sideBySide, browserEvent);
501+
this._open(preserveFocus, isDoubleClick || isMiddleClick, sideBySide, browserEvent);
501502
}
502503
}
503504

@@ -507,10 +508,10 @@ abstract class ResourceNavigator<T> extends Disposable {
507508
}
508509

509510
const sideBySide = (browserEvent.ctrlKey || browserEvent.metaKey || browserEvent.altKey);
510-
this.open(true, true, sideBySide, browserEvent);
511+
this._open(true, true, sideBySide, browserEvent);
511512
}
512513

513-
private open(preserveFocus: boolean, pinned: boolean, sideBySide: boolean, browserEvent?: UIEvent): void {
514+
private _open(preserveFocus: boolean, pinned: boolean, sideBySide: boolean, browserEvent?: UIEvent): void {
514515
this._onDidOpen.fire({
515516
editorOptions: {
516517
preserveFocus,
@@ -522,6 +523,11 @@ abstract class ResourceNavigator<T> extends Disposable {
522523
browserEvent
523524
});
524525
}
526+
527+
// hack for References Widget: pressing Enter on already selected tree element
528+
open(browserEvent?: UIEvent): void {
529+
this._open((browserEvent as any)?.preserveFocus || false, true, false, browserEvent);
530+
}
525531
}
526532

527533
export class ListResourceNavigator<T> extends ResourceNavigator<number> {
@@ -594,6 +600,10 @@ export class WorkbenchObjectTree<T extends NonNullable<any>, TFilterData = void>
594600
this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
595601
this.disposables.add(this.internals);
596602
}
603+
604+
open(browserEvent?: UIEvent): void {
605+
this.internals.open(browserEvent);
606+
}
597607
}
598608

599609
export interface IWorkbenchCompressibleObjectTreeOptionsUpdate extends ICompressibleObjectTreeOptionsUpdate {
@@ -638,6 +648,10 @@ export class WorkbenchCompressibleObjectTree<T extends NonNullable<any>, TFilter
638648
this.internals.updateStyleOverrides(options.overrideStyles);
639649
}
640650
}
651+
652+
open(browserEvent?: UIEvent): void {
653+
this.internals.open(browserEvent);
654+
}
641655
}
642656

643657
export interface IWorkbenchDataTreeOptionsUpdate extends IAbstractTreeOptionsUpdate {
@@ -683,6 +697,10 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T
683697
this.internals.updateStyleOverrides(options.overrideStyles);
684698
}
685699
}
700+
701+
open(browserEvent?: UIEvent): void {
702+
this.internals.open(browserEvent);
703+
}
686704
}
687705

688706
export interface IWorkbenchAsyncDataTreeOptionsUpdate extends IAsyncDataTreeOptionsUpdate {
@@ -728,6 +746,10 @@ export class WorkbenchAsyncDataTree<TInput, T, TFilterData = void> extends Async
728746
this.internals.updateStyleOverrides(options.overrideStyles);
729747
}
730748
}
749+
750+
open(browserEvent?: UIEvent): void {
751+
this.internals.open(browserEvent);
752+
}
731753
}
732754

733755
export interface IWorkbenchCompressibleAsyncDataTreeOptions<T, TFilterData> extends ICompressibleAsyncDataTreeOptions<T, TFilterData>, IResourceNavigatorOptions {
@@ -763,6 +785,10 @@ export class WorkbenchCompressibleAsyncDataTree<TInput, T, TFilterData = void> e
763785
this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
764786
this.disposables.add(this.internals);
765787
}
788+
789+
open(browserEvent?: UIEvent): void {
790+
this.internals.open(browserEvent);
791+
}
766792
}
767793

768794
function workbenchTreeDataPreamble<T, TFilterData, TOptions extends IAbstractTreeOptions<T, TFilterData> | IAsyncDataTreeOptions<T, TFilterData>>(
@@ -935,6 +961,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
935961
this.styler = overrideStyles ? attachListStyler(this.tree, this.themeService, overrideStyles) : Disposable.None;
936962
}
937963

964+
open(browserEvent?: UIEvent): void {
965+
this.navigator.open(browserEvent);
966+
}
967+
938968
dispose(): void {
939969
this.disposables = dispose(this.disposables);
940970
dispose(this.styler);

src/vs/workbench/browser/actions/listCommands.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,23 +506,24 @@ function focusElement(accessor: ServicesAccessor, retainCurrentFocus: boolean):
506506

507507
// Trees
508508
else if (focused instanceof ObjectTree || focused instanceof DataTree || focused instanceof AsyncDataTree) {
509-
const list = focused;
510-
const focus = list.getFocus();
509+
const tree = focused;
510+
const focus = tree.getFocus();
511511

512512
if (focus.length > 0) {
513513
let toggleCollapsed = true;
514514

515-
if (list.expandOnlyOnTwistieClick === true) {
515+
if (tree.expandOnlyOnTwistieClick === true) {
516516
toggleCollapsed = false;
517-
} else if (typeof list.expandOnlyOnTwistieClick !== 'boolean' && list.expandOnlyOnTwistieClick(focus[0])) {
517+
} else if (typeof tree.expandOnlyOnTwistieClick !== 'boolean' && tree.expandOnlyOnTwistieClick(focus[0])) {
518518
toggleCollapsed = false;
519519
}
520520

521521
if (toggleCollapsed) {
522-
list.toggleCollapsed(focus[0]);
522+
tree.toggleCollapsed(focus[0]);
523523
}
524524
}
525-
list.setSelection(focus, fakeKeyboardEvent);
525+
tree.setSelection(focus, fakeKeyboardEvent);
526+
tree.open(fakeKeyboardEvent);
526527
}
527528
}
528529

0 commit comments

Comments
 (0)