Skip to content

Commit

Permalink
fix #1707: check widget activation only for last widget, after 2s
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Aug 2, 2019
1 parent e911098 commit 80c4e86
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@phosphor/widgets';
import { Message } from '@phosphor/messaging';
import { IDragEvent } from '@phosphor/dragdrop';
import { RecursivePartial, MaybePromise, Event as CommonEvent } from '../../common';
import { RecursivePartial, MaybePromise, Event as CommonEvent, DisposableCollection, Disposable } from '../../common';
import { Saveable } from '../saveable';
import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar/status-bar';
import { TheiaDockPanel, BOTTOM_AREA_ID, MAIN_AREA_ID } from './theia-dock-panel';
Expand Down Expand Up @@ -865,7 +865,11 @@ export class ApplicationShell extends Widget {
* Track the given widget so it is considered in the `current` and `active` state of the shell.
*/
protected async track(widget: Widget): Promise<void> {
if (this.tracker.widgets.indexOf(widget) !== -1) {
return;
}
this.tracker.add(widget);
this.checkActivation(widget);
Saveable.apply(widget);
if (ApplicationShell.TrackableWidgetProvider.is(widget)) {
for (const toTrack of await widget.getTrackableWidgets()) {
Expand Down Expand Up @@ -915,7 +919,7 @@ export class ApplicationShell extends Widget {
current = child;
}
}
return current && this.checkActivation(current);
return current;
}

/**
Expand Down Expand Up @@ -951,14 +955,37 @@ export class ApplicationShell extends Widget {
* `activeWidget` property.
*/
private checkActivation(widget: Widget): Widget {
window.requestAnimationFrame(() => {
if (this.activeWidget !== widget) {
console.warn('Widget was activated, but did not accept focus: ' + widget.id);
}
});
const onActivateRequest = widget['onActivateRequest'].bind(widget);
widget['onActivateRequest'] = (msg: Message) => {
onActivateRequest(msg);
this.assertActivated(widget);
};
return widget;
}

private readonly activationTimeout = 2000;
private readonly toDisposeOnActivationCheck = new DisposableCollection();
private assertActivated(widget: Widget): void {
this.toDisposeOnActivationCheck.dispose();
let start = 0;
const step: FrameRequestCallback = timestamp => {
if (document.activeElement && widget.node.contains(document.activeElement)) {
return;
}
if (!start) {
start = timestamp;
}
const delta = timestamp - start;
if (delta < this.activationTimeout) {
request = window.requestAnimationFrame(step);
} else {
console.warn(`Widget was activated, but did not accept focus after ${this.activationTimeout}ms: ${widget.id}`);
}
};
let request = window.requestAnimationFrame(step);
this.toDisposeOnActivationCheck.push(Disposable.create(() => window.cancelAnimationFrame(request)));
}

/**
* Reveal a widget in the application shell. This makes the widget visible,
* but does not activate it.
Expand Down

0 comments on commit 80c4e86

Please sign in to comment.