Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse-keyboard event crossover to prevent menu bar from showing up after multi-selecting. #9154

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions src/vs/editor/browser/view/viewImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ import {IViewModel} from 'vs/editor/common/viewModel/viewModel';
import {ViewLinesViewportData} from 'vs/editor/common/viewLayout/viewLinesViewportData';
import {IRenderingContext} from 'vs/editor/common/view/renderingContext';
import {IPointerHandlerHelper} from 'vs/editor/browser/controller/mouseHandler';
import {lookupKeyCode} from 'vs/base/browser/keyboardEvent';
import {KeyCode} from 'vs/base/common/keyCodes';


class KeyboardMouseCrossoverStatus {
public altListeningMouse = false;
public altMouseTriggered = false;
}

export class View extends ViewEventHandler implements editorBrowser.IView, IDisposable {

Expand Down Expand Up @@ -90,6 +98,8 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
private _keybindingService: IKeybindingService;
private _editorTextFocusContextKey: IKeybindingContextKey<boolean>;

private _crossoverStatus: KeyboardMouseCrossoverStatus;

constructor(
keybindingService: IKeybindingService,
commandService: ICommandService,
Expand Down Expand Up @@ -136,11 +146,15 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
this.createTextArea(keybindingService);
this.createViewParts();

// Keyboard-Mouse Crossover Status
this._crossoverStatus = new KeyboardMouseCrossoverStatus;

// Keyboard handler
this.keyboardHandler = new KeyboardHandler(this._context, viewController, this.createKeyboardHandlerHelper());
this.keyboardHandler = new KeyboardHandler(this._context, viewController, this.createKeyboardHandlerHelper(this._crossoverStatus));

// Pointer handler
this.pointerHandler = new PointerHandler(this._context, viewController, this.createPointerHandlerHelper());
this.pointerHandler = new PointerHandler(this._context, viewController, this.createPointerHandlerHelper(this._crossoverStatus));


this.hasFocus = false;
this.codeEditorHelper = null;
Expand Down Expand Up @@ -292,7 +306,18 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
this._renderNow();
}

private createPointerHandlerHelper(): IPointerHandlerHelper {
private createPointerHandlerHelper(crossover: KeyboardMouseCrossoverStatus): IPointerHandlerHelper {
// A global crossover handler to prevent menu bar from showing up
this.domNode.onmousedown = function(orig){
return function(e){
if(crossover.altListeningMouse){
crossover.altMouseTriggered = true;
}
if(orig) {
return orig.apply(this, arguments);
}
};
}(this.domNode.onmousedown);
return {
viewDomNode: this.domNode,
linesContentDomNode: this.linesContent,
Expand Down Expand Up @@ -389,7 +414,37 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
};
}

private createKeyboardHandlerHelper(): IKeyboardHandlerHelper {
private createKeyboardHandlerHelper(crossover: KeyboardMouseCrossoverStatus): IKeyboardHandlerHelper {
// A global crossover handler to prevent menu bar from showing up
// When <alt> is hold, we will listen to mouse events and prevent
// the release event up <alt> if the mouse is triggered.
this.textArea.onkeydown = function(orig){
return function(e){
if(lookupKeyCode(e) === KeyCode.Alt){
if(!crossover.altListeningMouse){
crossover.altMouseTriggered = false;
}
crossover.altListeningMouse = true;
}
if(orig) {
return orig.apply(this, arguments);
}
};
}(this.textArea.onkeydown);
this.textArea.onkeyup = function(orig){
return function(e){
if(lookupKeyCode(e) === KeyCode.Alt){
if(crossover.altMouseTriggered){
e.preventDefault();
}
crossover.altListeningMouse = false;
crossover.altMouseTriggered = false;
}
if(orig) {
return orig.apply(this, arguments);
}
};
}(this.textArea.onkeyup);
return {
viewDomNode: this.domNode,
textArea: this.textArea,
Expand Down