提交 68d09509 编写于 作者: B Benjamin Pasero

Up/down in notifications should reset focus (fixes #44587)

上级 c8893033
......@@ -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;
}
......
......@@ -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
......@@ -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
......@@ -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();
}
......
......@@ -60,7 +60,7 @@ export interface ITree {
/**
* Sets DOM focus on the tree.
*/
DOMFocus(): void;
domFocus(): void;
/**
* Returns whether the tree has DOM focus.
......@@ -70,7 +70,7 @@ export interface ITree {
/**
* Removes DOM focus from the tree.
*/
DOMBlur(): void;
domBlur(): void;
/**
* Refreshes an element.
......
......@@ -172,7 +172,7 @@ export class DefaultController implements _.IController {
}
eventish.stopPropagation();
tree.DOMFocus();
tree.domFocus();
tree.setSelection([element], payload);
tree.setFocus(element, payload);
......@@ -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);
......
......@@ -126,7 +126,7 @@ export class Tree implements _.ITree {
this.view.layout(height);
}
public DOMFocus(): void {
public domFocus(): void {
this.view.focus();
}
......@@ -134,7 +134,7 @@ export class Tree implements _.ITree {
return this.view.isFocused();
}
public DOMBlur(): void {
public domBlur(): void {
this.view.blur();
}
......
......@@ -575,7 +575,7 @@ export class ReferenceWidget extends PeekViewWidget {
}
focus(): void {
this._tree.DOMFocus();
this._tree.domFocus();
}
protected _onTitleClick(e: MouseEvent): void {
......
......@@ -198,7 +198,7 @@ class CustomTreeViewer extends Disposable implements ITreeViewer {
}
// Pass Focus to Viewer
this.tree.DOMFocus();
this.tree.domFocus();
}
}
......@@ -541,7 +541,7 @@ class TreeController extends WorkbenchTreeController {
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
},
......
......@@ -161,7 +161,7 @@ export abstract class TreeViewsViewletPanel extends ViewsViewletPanel {
}
// Pass Focus to Viewer
this.tree.DOMFocus();
this.tree.domFocus();
}
dispose(): void {
......
......@@ -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);
......
......@@ -18,7 +18,7 @@ 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';
......@@ -26,12 +26,25 @@ 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;
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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;
......
......@@ -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.
......@@ -229,7 +229,7 @@ export class BaseDebugController extends WorkbenchTreeController {
}),
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
},
getActionsContext: () => element
......
......@@ -281,7 +281,7 @@ export class DebugHoverWidget implements IContentWidget {
this.scrollbar.scanDomNode();
if (focus) {
this.editor.render();
this.tree.DOMFocus();
this.tree.domFocus();
}
});
}
......
......@@ -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) {
......@@ -878,7 +878,7 @@ class CopyFileAction extends BaseFileAction {
this.tree.clearHighlight();
}
this.tree.DOMFocus();
this.tree.domFocus();
return TPromise.as(null);
}
......@@ -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")));
......@@ -1221,7 +1221,7 @@ export class FocusFilesExplorer extends Action {
const view = viewlet.getExplorerView();
if (view) {
view.setExpanded(true);
view.getViewer().DOMFocus();
view.getViewer().domFocus();
}
});
}
......
......@@ -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));
......
......@@ -299,7 +299,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}
// Pass Focus to Viewer
this.explorerViewer.DOMFocus();
this.explorerViewer.domFocus();
keepFocus = true;
}
......@@ -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);
}
......@@ -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;
......
......@@ -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);
......@@ -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;
}
......@@ -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
......
......@@ -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();
}
......
......@@ -66,7 +66,7 @@ export class Controller extends WorkbenchTreeController {
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.DOMFocus();
tree.domFocus();
}
}
});
......
......@@ -377,7 +377,7 @@ export class CollapseDeepestExpandedLevelAction extends Action {
viewer.collapseDeepestExpandedLevel();
viewer.clearSelection();
viewer.clearFocus();
viewer.DOMFocus();
viewer.domFocus();
viewer.focusFirst();
}
return TPromise.as(null);
......@@ -548,7 +548,7 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
elementToRefresh = parent.count() === 0 ? parent.parent() : parent;
}
this.viewer.DOMFocus();
this.viewer.domFocus();
return this.viewer.refresh(elementToRefresh);
}
......@@ -567,7 +567,7 @@ export class ReplaceAllAction extends AbstractSearchAndReplaceAction {
if (nextFocusElement) {
this.viewer.setFocus(nextFocusElement);
}
this.viewer.DOMFocus();
this.viewer.domFocus();
this.viewlet.open(this.fileMatch, true);
});
}
......@@ -588,7 +588,7 @@ export class ReplaceAllInFolderAction extends AbstractSearchAndReplaceAction {
if (nextFocusElement) {
this.viewer.setFocus(nextFocusElement);
}
this.viewer.DOMFocus();
this.viewer.domFocus();
}
}
......@@ -610,7 +610,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
this.viewer.setFocus(elementToFocus);
}
let elementToShowReplacePreview = this.getElementToShowReplacePreview(elementToFocus);
this.viewer.DOMFocus();
this.viewer.domFocus();
if (!elementToShowReplacePreview || this.hasToOpenFile()) {
this.viewlet.open(this.element, true);
} else {
......
......@@ -827,7 +827,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
private selectTreeIfNotSelected(): void {
if (this.tree.getInput()) {
this.tree.DOMFocus();
this.tree.domFocus();
let selection = this.tree.getSelection();
if (selection.length === 0) {
this.tree.focusNext();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册