From 3118955ee8ec18cdd3eb0d8cd07990c8cdc3b9b2 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 17 Sep 2020 11:07:33 +0200 Subject: [PATCH] debug: when the alt key is pressed show regular editor hover and hide the debug hover #84561 --- .../debug/browser/debugEditorContribution.ts | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts index a2c9b9a3164..d103567a26d 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts @@ -10,7 +10,7 @@ import { visit } from 'vs/base/common/json'; import { setProperty } from 'vs/base/common/jsonEdit'; import { Constants } from 'vs/base/common/uint'; import { KeyCode } from 'vs/base/common/keyCodes'; -import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; +import { IKeyboardEvent, StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { StandardTokenType } from 'vs/editor/common/modes'; import { DEFAULT_WORD_REGEXP } from 'vs/editor/common/model/wordHelper'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType, IPartialEditorMouseEvent } from 'vs/editor/browser/editorBrowser'; @@ -33,6 +33,7 @@ import { ITextModel } from 'vs/editor/common/model'; import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { EditOperation } from 'vs/editor/common/core/editOperation'; import { basename } from 'vs/base/common/path'; +import { domEvent } from 'vs/base/browser/event'; const HOVER_DELAY = 300; const LAUNCH_JSON_REGEX = /\.vscode\/launch\.json$/; @@ -171,8 +172,9 @@ export class DebugEditorContribution implements IDebugEditorContribution { private static readonly MEMOIZER = createMemoizer(); private exceptionWidget: ExceptionWidget | undefined; - private configurationWidget: FloatingClickWidget | undefined; + private altListener: IDisposable | undefined; + private altPressed = false; constructor( private editor: ICodeEditor, @@ -219,7 +221,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { const stackFrame = this.debugService.getViewModel().focusedStackFrame; const model = this.editor.getModel(); if (model) { - this._applyHoverConfiguration(model, stackFrame); + this.applyHoverConfiguration(model, stackFrame); } this.toggleExceptionWidget(); this.hideHoverWidget(); @@ -240,14 +242,38 @@ export class DebugEditorContribution implements IDebugEditorContribution { return getWordToLineNumbersMap(this.editor.getModel()); } - private _applyHoverConfiguration(model: ITextModel, stackFrame: IStackFrame | undefined): void { + private applyHoverConfiguration(model: ITextModel, stackFrame: IStackFrame | undefined): void { if (stackFrame && model.uri.toString() === stackFrame.source.uri.toString()) { - this.editor.updateOptions({ - hover: { - enabled: false + if (this.altListener) { + this.altListener.dispose(); + } + // When the alt key is pressed show regular editor hover and hide the debug hover #84561 + this.altListener = domEvent(document, 'keydown')(keydownEvent => { + const standardKeyboardEvent = new StandardKeyboardEvent(keydownEvent); + if (standardKeyboardEvent.keyCode === KeyCode.Alt) { + this.altPressed = true; + this.hoverWidget.hide(); + this.enableEditorHover(); + const listener = domEvent(document, 'keyup')(keyupEvent => { + const standardKeyboardEvent = new StandardKeyboardEvent(keyupEvent); + if (standardKeyboardEvent.keyCode === KeyCode.Alt) { + this.altPressed = false; + this.editor.updateOptions({ hover: { enabled: false } }); + listener.dispose(); + } + }); } }); + + this.editor.updateOptions({ hover: { enabled: false } }); } else { + this.enableEditorHover(); + } + } + + private enableEditorHover(): void { + if (this.editor.hasModel()) { + const model = this.editor.getModel(); let overrides = { resource: model.uri, overrideIdentifier: model.getLanguageIdentifier().language @@ -266,7 +292,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { async showHover(range: Range, focus: boolean): Promise { const sf = this.debugService.getViewModel().focusedStackFrame; const model = this.editor.getModel(); - if (sf && model && sf.source.uri.toString() === model.uri.toString()) { + if (sf && model && sf.source.uri.toString() === model.uri.toString() && !this.altPressed) { return this.hoverWidget.showAt(range, focus); } } @@ -274,7 +300,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { private async onFocusStackFrame(sf: IStackFrame | undefined): Promise { const model = this.editor.getModel(); if (model) { - this._applyHoverConfiguration(model, sf); + this.applyHoverConfiguration(model, sf); if (sf && sf.source.uri.toString() === model.uri.toString()) { await this.toggleExceptionWidget(); } else { -- GitLab