Skip to content

Commit

Permalink
debug: when the alt key is pressed show regular editor hover and hide…
Browse files Browse the repository at this point in the history
… the debug hover

#84561
  • Loading branch information
isidorn committed Sep 17, 2020
1 parent 3808cb3 commit 3118955
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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$/;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -266,15 +292,15 @@ export class DebugEditorContribution implements IDebugEditorContribution {
async showHover(range: Range, focus: boolean): Promise<void> {
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);
}
}

private async onFocusStackFrame(sf: IStackFrame | undefined): Promise<void> {
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 {
Expand Down

0 comments on commit 3118955

Please sign in to comment.