Skip to content

Commit

Permalink
Fixes microsoft/monaco-editor#146: Cancel focus timeout if the view g…
Browse files Browse the repository at this point in the history
…ets disposed
  • Loading branch information
alexdima committed Sep 2, 2016
1 parent 5430176 commit 22dccab
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/vs/editor/browser/controller/mouseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {ViewEventHandler} from 'vs/editor/common/viewModel/viewEventHandler';
import {MouseTargetFactory} from 'vs/editor/browser/controller/mouseTarget';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import {TimeoutTimer} from 'vs/base/common/async';
import {TimeoutTimer, RunOnceScheduler} from 'vs/base/common/async';
import {ViewContext} from 'vs/editor/common/view/viewContext';
import {VisibleRange} from 'vs/editor/common/view/renderingContext';
import {EditorMouseEventFactory, GlobalEditorMouseMoveMonitor, EditorMouseEvent} from 'vs/editor/browser/editorDom';
Expand Down Expand Up @@ -131,6 +131,7 @@ export class MouseHandler extends ViewEventHandler implements IDisposable {
protected mouseTargetFactory: MouseTargetFactory;
protected listenersToRemove:IDisposable[];
private toDispose:IDisposable[];
private _asyncFocus: RunOnceScheduler;

private _mouseDownOperation: MouseDownOperation;
private lastMouseLeaveTime:number;
Expand All @@ -155,6 +156,8 @@ export class MouseHandler extends ViewEventHandler implements IDisposable {
);

this.toDispose = [];
this._asyncFocus = new RunOnceScheduler(() => this.viewHelper.focusTextArea(), 0);
this.toDispose.push(this._asyncFocus);

this.lastMouseLeaveTime = -1;

Expand Down Expand Up @@ -214,6 +217,11 @@ export class MouseHandler extends ViewEventHandler implements IDisposable {
this._mouseDownOperation.onCursorSelectionChanged(e);
return false;
}
private _isFocused = false;
public onViewFocusChanged(isFocused:boolean): boolean {
this._isFocused = isFocused;
return false;
}
// --- end event handlers

protected _createMouseTarget(e:EditorMouseEvent, testEventTarget:boolean): editorBrowser.IMouseTarget {
Expand Down Expand Up @@ -280,17 +288,11 @@ export class MouseHandler extends ViewEventHandler implements IDisposable {
}

var focus = () => {
if (browser.isIE11orEarlier) {
// IE does not want to focus when coming in from the browser's address bar
if ((<any>e.browserEvent).fromElement) {
e.preventDefault();
this.viewHelper.focusTextArea();
} else {
// TODO@Alex -> cancel this if focus is lost
setTimeout(() => {
this.viewHelper.focusTextArea();
});
}
// In IE11, if the focus is in the browser's address bar and
// then you click in the editor, calling preventDefault()
// will not move focus properly (focus remains the address bar)
if (browser.isIE11orEarlier && !this._isFocused) {
this._asyncFocus.schedule();
} else {
e.preventDefault();
this.viewHelper.focusTextArea();
Expand Down

0 comments on commit 22dccab

Please sign in to comment.