From 0619eec01bdea1a7052dd18ff32d939da7e55002 Mon Sep 17 00:00:00 2001 From: be5invis Date: Wed, 13 Jul 2016 02:52:35 +0800 Subject: [PATCH 1/2] Add mouse-keyboard crossover to prevent menu bar from showing up. --- src/vs/editor/browser/view/viewImpl.ts | 57 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index c71b44ac37474..d210088ce79c9 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -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, KeyMod} from 'vs/base/common/keyCodes'; + + +class KeyboardMouseCrossoverStatus { + public altListeningMouse = false; + public altMouseTriggered = false; +} export class View extends ViewEventHandler implements editorBrowser.IView, IDisposable { @@ -90,6 +98,8 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp private _keybindingService: IKeybindingService; private _editorTextFocusContextKey: IKeybindingContextKey; + private _crossoverStatus: KeyboardMouseCrossoverStatus; + constructor( keybindingService: IKeybindingService, commandService: ICommandService, @@ -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; @@ -292,7 +306,16 @@ 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) orig.apply(this, arguments); + } + }(this.domNode.onmousedown); return { viewDomNode: this.domNode, linesContentDomNode: this.linesContent, @@ -389,7 +412,33 @@ 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 is hold, we will listen to mouse events and prevent + // the release event up 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) 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) orig.apply(this, arguments); + } + }(this.textArea.onkeyup); return { viewDomNode: this.domNode, textArea: this.textArea, From 1c2097b51e8541504c0218cd45bd3314328a523e Mon Sep 17 00:00:00 2001 From: be5invis Date: Wed, 13 Jul 2016 04:19:51 +0800 Subject: [PATCH 2/2] format --- src/vs/editor/browser/view/viewImpl.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index d210088ce79c9..403ff981df276 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -47,7 +47,7 @@ import {ViewLinesViewportData} from 'vs/editor/common/viewLayout/viewLinesViewpo 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, KeyMod} from 'vs/base/common/keyCodes'; +import {KeyCode} from 'vs/base/common/keyCodes'; class KeyboardMouseCrossoverStatus { @@ -313,8 +313,10 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp if(crossover.altListeningMouse){ crossover.altMouseTriggered = true; } - if(orig) orig.apply(this, arguments); - } + if(orig) { + return orig.apply(this, arguments); + } + }; }(this.domNode.onmousedown); return { viewDomNode: this.domNode, @@ -418,26 +420,30 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp // the release event up if the mouse is triggered. this.textArea.onkeydown = function(orig){ return function(e){ - if(lookupKeyCode(e) == KeyCode.Alt){ + if(lookupKeyCode(e) === KeyCode.Alt){ if(!crossover.altListeningMouse){ crossover.altMouseTriggered = false; } crossover.altListeningMouse = true; } - if(orig) orig.apply(this, arguments); - } + if(orig) { + return orig.apply(this, arguments); + } + }; }(this.textArea.onkeydown); this.textArea.onkeyup = function(orig){ return function(e){ - if(lookupKeyCode(e) == KeyCode.Alt){ + if(lookupKeyCode(e) === KeyCode.Alt){ if(crossover.altMouseTriggered){ e.preventDefault(); } crossover.altListeningMouse = false; crossover.altMouseTriggered = false; } - if(orig) orig.apply(this, arguments); - } + if(orig) { + return orig.apply(this, arguments); + } + }; }(this.textArea.onkeyup); return { viewDomNode: this.domNode,