Skip to content

Commit

Permalink
Up/down in notifications should reset focus (fixes #44587)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 2, 2018
1 parent c889303 commit 68d0950
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 37 deletions.
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/list/listPaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class PagedList<T> implements IDisposable {
return this.list.getHTMLElement() === document.activeElement;
}

domFocus(): void {
this.list.domFocus();
}

get onDidFocus(): Event<void> {
return this.list.onDidFocus;
}
Expand Down
6 changes: 3 additions & 3 deletions src/vs/base/parts/quickopen/browser/quickOpenWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class QuickOpenWidget implements IModelProvider {
// Transition into quick navigate mode if not yet done
if (!this.quickNavigateConfiguration && quickNavigate) {
this.quickNavigateConfiguration = quickNavigate;
this.tree.DOMFocus();
this.tree.domFocus();
}

// Navigate
Expand Down Expand Up @@ -558,7 +558,7 @@ export class QuickOpenWidget implements IModelProvider {
if (this.quickNavigateConfiguration) {
this.inputContainer.hide();
this.builder.show();
this.tree.DOMFocus();
this.tree.domFocus();
}

// Otherwise use normal UI
Expand Down Expand Up @@ -783,7 +783,7 @@ export class QuickOpenWidget implements IModelProvider {

// Clear Focus
if (this.tree.isDOMFocused()) {
this.tree.DOMBlur();
this.tree.domBlur();
} else if (this.inputBox.hasFocus()) {
this.inputBox.blur();
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/parts/tree/browser/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface ITree {
/**
* Sets DOM focus on the tree.
*/
DOMFocus(): void;
domFocus(): void;

/**
* Returns whether the tree has DOM focus.
Expand All @@ -70,7 +70,7 @@ export interface ITree {
/**
* Removes DOM focus from the tree.
*/
DOMBlur(): void;
domBlur(): void;

/**
* Refreshes an element.
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/parts/tree/browser/treeDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class DefaultController implements _.IController {
}
eventish.stopPropagation();

tree.DOMFocus();
tree.domFocus();
tree.setSelection([element], payload);
tree.setFocus(element, payload);

Expand Down Expand Up @@ -458,7 +458,7 @@ export class CollapseAllAction extends Action {
this.viewer.collapseAll();
this.viewer.clearSelection();
this.viewer.clearFocus();
this.viewer.DOMFocus();
this.viewer.domFocus();
this.viewer.focusFirst();

return TPromise.as(null);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/parts/tree/browser/treeImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export class Tree implements _.ITree {
this.view.layout(height);
}

public DOMFocus(): void {
public domFocus(): void {
this.view.focus();
}

public isDOMFocused(): boolean {
return this.view.isFocused();
}

public DOMBlur(): void {
public domBlur(): void {
this.view.blur();
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/referenceSearch/referencesWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export class ReferenceWidget extends PeekViewWidget {
}

focus(): void {
this._tree.DOMFocus();
this._tree.domFocus();
}

protected _onTitleClick(e: MouseEvent): void {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/views/customView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class CustomTreeViewer extends Disposable implements ITreeViewer {
}

// Pass Focus to Viewer
this.tree.DOMFocus();
this.tree.domFocus();
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ class TreeController extends WorkbenchTreeController {

onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/views/viewsViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export abstract class TreeViewsViewletPanel extends ViewsViewletPanel {
}

// Pass Focus to Viewer
this.tree.DOMFocus();
this.tree.domFocus();
}

dispose(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/viewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class CollapseAction extends Action {
viewer.collapseAll();
viewer.clearSelection();
viewer.clearFocus();
viewer.DOMFocus();
viewer.domFocus();
viewer.focusFirst();

return TPromise.as(null);
Expand Down
30 changes: 29 additions & 1 deletion src/vs/workbench/electron-browser/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,33 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import URI from 'vs/base/common/uri';
import { IEditorOptions, Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { WorkbenchListFocusContextKey, IListService, WorkbenchListSupportsMultiSelectContextKey } from 'vs/platform/list/browser/listService';
import { WorkbenchListFocusContextKey, IListService, WorkbenchListSupportsMultiSelectContextKey, ListWidget } from 'vs/platform/list/browser/listService';
import { PagedList } from 'vs/base/browser/ui/list/listPaging';
import { range } from 'vs/base/common/arrays';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ITree } from 'vs/base/parts/tree/browser/tree';

// --- List Commands

function ensureDOMFocus(widget: ListWidget): void {
// it can happen that one of the commands is executed while
// DOM focus is within another focusable control within the
// list/tree item. therefor we should ensure that the
// list/tree has DOM focus again after the command ran.
if (widget && !widget.isDOMFocused()) {
widget.domFocus();
}
}

export function registerCommands(): void {

function focusDown(accessor: ServicesAccessor, arg2?: number): void {
const focused = accessor.get(IListService).lastFocusedList;
const count = typeof arg2 === 'number' ? arg2 : 1;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand Down Expand Up @@ -131,6 +144,9 @@ export function registerCommands(): void {
const focused = accessor.get(IListService).lastFocusedList;
const count = typeof arg2 === 'number' ? arg2 : 1;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand Down Expand Up @@ -261,6 +277,9 @@ export function registerCommands(): void {
handler: (accessor) => {
const focused = accessor.get(IListService).lastFocusedList;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand All @@ -287,6 +306,9 @@ export function registerCommands(): void {
handler: (accessor) => {
const focused = accessor.get(IListService).lastFocusedList;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand Down Expand Up @@ -324,6 +346,9 @@ export function registerCommands(): void {
function listFocusFirst(accessor: ServicesAccessor, options?: { fromFocused: boolean }): void {
const focused = accessor.get(IListService).lastFocusedList;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand Down Expand Up @@ -360,6 +385,9 @@ export function registerCommands(): void {
function listFocusLast(accessor: ServicesAccessor, options?: { fromFocused: boolean }): void {
const focused = accessor.get(IListService).lastFocusedList;

// Ensure DOM Focus
ensureDOMFocus(focused);

// List
if (focused instanceof List || focused instanceof PagedList) {
const list = focused;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/debug/browser/baseDebugView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function renderRenameBox(debugService: IDebugService, contextViewService:
}
}

tree.DOMFocus();
tree.domFocus();
tree.setFocus(element);

// need to remove the input box since this template will be reused.
Expand Down Expand Up @@ -229,7 +229,7 @@ export class BaseDebugController extends WorkbenchTreeController {
}),
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
},
getActionsContext: () => element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class DebugHoverWidget implements IContentWidget {
this.scrollbar.scanDomNode();
if (focus) {
this.editor.render();
this.tree.DOMFocus();
this.tree.domFocus();
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/files/electron-browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ class BaseDeleteFileAction extends BaseFileAction {
return this.choiceService.choose(Severity.Error, toErrorMessage(error, false), choices, choices.length - 1, true).then(choice => {

// Focus back to tree
this.tree.DOMFocus();
this.tree.domFocus();


if (this.useTrash) {
Expand Down Expand Up @@ -878,7 +878,7 @@ class CopyFileAction extends BaseFileAction {
this.tree.clearHighlight();
}

this.tree.DOMFocus();
this.tree.domFocus();

return TPromise.as(null);
}
Expand Down Expand Up @@ -942,7 +942,7 @@ class PasteFileAction extends BaseFileAction {

return void 0;
}, error => this.onError(error)).then(() => {
this.tree.DOMFocus();
this.tree.domFocus();
});
}, error => {
this.onError(new Error(nls.localize('fileDeleted', "File to paste was deleted or moved meanwhile")));
Expand Down Expand Up @@ -1221,7 +1221,7 @@ export class FocusFilesExplorer extends Action {
const view = viewlet.getExplorerView();
if (view) {
view.setExpanded(true);
view.getViewer().DOMFocus();
view.getViewer().domFocus();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ CommandsRegistry.registerCommand({
// Remove highlight
if (tree instanceof Tree) {
tree.clearHighlight();
tree.DOMFocus();
tree.domFocus();
}

globalResourceToCompare = getResourceForCommand(resource, listService, accessor.get(IWorkbenchEditorService));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}

// Pass Focus to Viewer
this.explorerViewer.DOMFocus();
this.explorerViewer.domFocus();
keepFocus = true;
}

Expand Down Expand Up @@ -580,7 +580,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView

// Ensure viewer has keyboard focus if event originates from viewer
if (restoreFocus) {
this.explorerViewer.DOMFocus();
this.explorerViewer.domFocus();
}
}, errors.onUnexpectedError);
}
Expand Down Expand Up @@ -729,7 +729,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}

// Focus
this.explorerViewer.DOMFocus();
this.explorerViewer.domFocus();

// Find resource to focus from active editor input if set
let resourceToFocus: URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class FileRenderer implements IRenderer {

setTimeout(() => {
if (!blur) { // https://github.com/Microsoft/vscode/issues/20269
tree.DOMFocus();
tree.domFocus();
}
lifecycle.dispose(toDispose);
container.removeChild(label.element);
Expand Down Expand Up @@ -408,7 +408,7 @@ export class FileController extends WorkbenchTreeController implements IDisposab
event.stopPropagation();

// Set DOM focus
tree.DOMFocus();
tree.domFocus();
if (stat instanceof NewStatPlaceholder) {
return true;
}
Expand Down Expand Up @@ -497,7 +497,7 @@ export class FileController extends WorkbenchTreeController implements IDisposab
},
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
},
getActionsContext: () => selection && selection.indexOf(stat) >= 0
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/markers/browser/markersPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MarkersPanel extends Panel {
}

if (this.markersWorkbenchService.markersModel.hasFilteredResources()) {
this.tree.DOMFocus();
this.tree.domFocus();
if (this.tree.getSelection().length === 0) {
this.tree.focusFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Controller extends WorkbenchTreeController {

onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
}
});
Expand Down
Loading

0 comments on commit 68d0950

Please sign in to comment.