fix references widget

上级 a790f912
......@@ -1099,12 +1099,6 @@ class TreeNodeListMouseController<T, TFilterData, TRef> extends MouseController<
}
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;
if (typeof this.tree.expandOnlyOnTwistieClick === 'function') {
......
......@@ -317,6 +317,8 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
accessibilityProvider: new AccessibilityProvider(),
keyboardNavigationLabelProvider: this._instantiationService.createInstance(StringRepresentationProvider),
identityProvider: new IdentityProvider(),
openOnSingleClick: true,
openOnFocus: true,
overrideStyles: {
listBackground: peekView.peekViewResultsBackground
}
......@@ -372,21 +374,12 @@ export class ReferenceWidget extends peekView.PeekViewWidget {
this._onDidSelectReference.fire({ element, kind, source: 'tree' });
}
};
this._tree.onDidChangeFocus(e => {
onEvent(e.elements[0], 'show');
});
this._tree.onDidOpen(e => {
if (e.browserEvent instanceof MouseEvent && (e.browserEvent.ctrlKey || e.browserEvent.metaKey || e.browserEvent.altKey)) {
// modifier-click -> open to the side
if (e.sideBySide) {
onEvent(e.element, 'side');
} else if (e.browserEvent instanceof KeyboardEvent || (e.browserEvent instanceof MouseEvent && e.browserEvent.detail === 2) || (<GestureEvent>e.browserEvent).tapCount === 2) {
// keybinding (list service command)
// OR double click
// OR double tap
// -> close widget and goto target
} else if (e.editorOptions.pinned) {
onEvent(e.element, 'goto');
} else {
// preview location
onEvent(e.element, 'show');
}
});
......
......@@ -28,6 +28,7 @@ import { IKeyboardNavigationEventFilter, IAbstractTreeOptions, RenderIndentGuide
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 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');
......@@ -38,11 +39,11 @@ export interface IListService {
/**
* Returns the currently focused list widget if any.
*/
readonly lastFocusedList: ListWidget | undefined;
readonly lastFocusedList: WorkbenchListWidget | undefined;
}
interface IRegisteredList {
widget: ListWidget;
widget: WorkbenchListWidget;
extraContextKeys?: (IContextKey<boolean>)[];
}
......@@ -52,17 +53,17 @@ export class ListService implements IListService {
private disposables = new DisposableStore();
private lists: IRegisteredList[] = [];
private _lastFocusedWidget: ListWidget | undefined = undefined;
private _lastFocusedWidget: WorkbenchListWidget | undefined = undefined;
private _hasCreatedStyleController: boolean = false;
get lastFocusedList(): ListWidget | undefined {
get lastFocusedList(): WorkbenchListWidget | undefined {
return this._lastFocusedWidget;
}
constructor(@IThemeService private readonly _themeService: IThemeService) {
}
register(widget: ListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable {
register(widget: WorkbenchListWidget, extraContextKeys?: (IContextKey<boolean>)[]): IDisposable {
if (!this._hasCreatedStyleController) {
this._hasCreatedStyleController = true;
// create a shared default tree style sheet for performance reasons
......@@ -477,7 +478,7 @@ abstract class ResourceNavigator<T> extends Disposable {
!!(<SelectionKeyboardEvent>browserEvent).preserveFocus :
true;
this.open(preserveFocus, false, false, browserEvent);
this._open(preserveFocus, false, false, browserEvent);
}
}
......@@ -497,7 +498,7 @@ abstract class ResourceNavigator<T> extends Disposable {
if (this.openOnSingleClick || isDoubleClick || isKeyboardEvent) {
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 {
}
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({
editorOptions: {
preserveFocus,
......@@ -522,6 +523,11 @@ abstract class ResourceNavigator<T> extends Disposable {
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> {
......@@ -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.disposables.add(this.internals);
}
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
}
export interface IWorkbenchCompressibleObjectTreeOptionsUpdate extends ICompressibleObjectTreeOptionsUpdate {
......@@ -638,6 +648,10 @@ export class WorkbenchCompressibleObjectTree<T extends NonNullable<any>, TFilter
this.internals.updateStyleOverrides(options.overrideStyles);
}
}
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
}
export interface IWorkbenchDataTreeOptionsUpdate extends IAbstractTreeOptionsUpdate {
......@@ -683,6 +697,10 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T
this.internals.updateStyleOverrides(options.overrideStyles);
}
}
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
}
export interface IWorkbenchAsyncDataTreeOptionsUpdate extends IAsyncDataTreeOptionsUpdate {
......@@ -728,6 +746,10 @@ export class WorkbenchAsyncDataTree<TInput, T, TFilterData = void> extends Async
this.internals.updateStyleOverrides(options.overrideStyles);
}
}
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
}
export interface IWorkbenchCompressibleAsyncDataTreeOptions<T, TFilterData> extends ICompressibleAsyncDataTreeOptions<T, TFilterData>, IResourceNavigatorOptions {
......@@ -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.disposables.add(this.internals);
}
open(browserEvent?: UIEvent): void {
this.internals.open(browserEvent);
}
}
function workbenchTreeDataPreamble<T, TFilterData, TOptions extends IAbstractTreeOptions<T, TFilterData> | IAsyncDataTreeOptions<T, TFilterData>>(
......@@ -935,6 +961,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
this.styler = overrideStyles ? attachListStyler(this.tree, this.themeService, overrideStyles) : Disposable.None;
}
open(browserEvent?: UIEvent): void {
this.navigator.open(browserEvent);
}
dispose(): void {
this.disposables = dispose(this.disposables);
dispose(this.styler);
......
......@@ -506,23 +506,24 @@ function focusElement(accessor: ServicesAccessor, retainCurrentFocus: boolean):
// Trees
else if (focused instanceof ObjectTree || focused instanceof DataTree || focused instanceof AsyncDataTree) {
const list = focused;
const focus = list.getFocus();
const tree = focused;
const focus = tree.getFocus();
if (focus.length > 0) {
let toggleCollapsed = true;
if (list.expandOnlyOnTwistieClick === true) {
if (tree.expandOnlyOnTwistieClick === true) {
toggleCollapsed = false;
} else if (typeof list.expandOnlyOnTwistieClick !== 'boolean' && list.expandOnlyOnTwistieClick(focus[0])) {
} else if (typeof tree.expandOnlyOnTwistieClick !== 'boolean' && tree.expandOnlyOnTwistieClick(focus[0])) {
toggleCollapsed = false;
}
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.
先完成此消息的编辑!
想要评论请 注册