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

editor - update style and behaviour of message widget #186480

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/vs/editor/contrib/message/browser/messageController.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@
}

.monaco-editor .monaco-editor-overlaymessage .message {
padding: 1px 4px;
color: var(--vscode-inputValidation-infoForeground);
background-color: var(--vscode-inputValidation-infoBackground);
padding: 2px 4px;
color: var(--vscode-editorHoverWidget-foreground);
background-color: var(--vscode-editorHoverWidget-background);
border: 1px solid var(--vscode-inputValidation-infoBorder);
border-radius: 3px;
}

.monaco-editor .monaco-editor-overlaymessage .message p {
margin-block: 0px;
}

.monaco-editor .monaco-editor-overlaymessage .message a {
font-weight: bold;
color: var(--vscode-inputValidation-infoForeground);
color: var(--vscode-textLink-foreground);
}

.monaco-editor .monaco-editor-overlaymessage .message a:hover {
color: var(--vscode-textLink-activeForeground);
}

.monaco-editor.hc-black .monaco-editor-overlaymessage .message,
Expand All @@ -59,6 +63,7 @@
z-index: 1000;
border-width: 8px;
position: absolute;
left: 2px;
}

.monaco-editor .monaco-editor-overlaymessage .anchor.top {
Expand Down
25 changes: 14 additions & 11 deletions src/vs/editor/contrib/message/browser/messageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
import { alert } from 'vs/base/browser/ui/aria/aria';
import { TimeoutTimer } from 'vs/base/common/async';
import { Event } from 'vs/base/common/event';
import { IMarkdownString, isMarkdownString } from 'vs/base/common/htmlContent';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class MessageController implements IEditorContribution {
private readonly _messageWidget = new MutableDisposable<MessageWidget>();
private readonly _messageListeners = new DisposableStore();
private _message: { element: HTMLElement; dispose: () => void } | undefined;
private _focus: boolean = false;
private _mouseOverMessage: boolean = false;

constructor(
editor: ICodeEditor,
Expand Down Expand Up @@ -76,21 +76,24 @@ export class MessageController implements IEditorContribution {
}) : undefined;
this._messageWidget.value = new MessageWidget(this._editor, position, typeof message === 'string' ? message : this._message!.element);

// close on blur, cursor, model change, dispose
this._messageListeners.add(this._editor.onDidBlurEditorText(() => {
if (!this._focus) {
this.closeMessage();
// close on blur (debounced to allow to tab into the message), cursor, model change, dispose
this._messageListeners.add(Event.debounce(this._editor.onDidBlurEditorText, (last, event) => event, 0)(() => {
if (this._mouseOverMessage) {
Copy link
Member

@jrieken jrieken Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you could get away without this property and check. The editor can tell you if it has text or widget focus and because the message is content widget focusing it will mean the editor signals widget focus (hasWidgetFocus)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think my intent is to preserve as much of the behaviour today, where the message widget should not remain visible too much, but the only exception is when focus goes into the message widget, specifically when there is a link and you tab into the message to execute it:

Recording 2023-06-28 at 14 51 37

Since the event order without debouncing will be that blur is emitted first, we would otherwise eagerly close the message widget, even though it is in the process of receiving focus.

return; // override when mouse over message
}

if (this._messageWidget.value && dom.isAncestor(document.activeElement, this._messageWidget.value.getDomNode())) {
return; // override when focus is inside the message
}

this.closeMessage();
}
));
this._messageListeners.add(this._editor.onDidChangeCursorPosition(() => this.closeMessage()));
this._messageListeners.add(this._editor.onDidDispose(() => this.closeMessage()));
this._messageListeners.add(this._editor.onDidChangeModel(() => this.closeMessage()));
this._messageListeners.add(dom.addDisposableListener(this._messageWidget.value.getDomNode(), dom.EventType.MOUSE_ENTER, () => this._focus = true, true));
this._messageListeners.add(dom.addDisposableListener(this._messageWidget.value.getDomNode(), dom.EventType.MOUSE_LEAVE, () => this._focus = false, true));

// 3sec
this._messageListeners.add(new TimeoutTimer(() => this.closeMessage(), 3000));
this._messageListeners.add(dom.addDisposableListener(this._messageWidget.value.getDomNode(), dom.EventType.MOUSE_ENTER, () => this._mouseOverMessage = true, true));
this._messageListeners.add(dom.addDisposableListener(this._messageWidget.value.getDomNode(), dom.EventType.MOUSE_LEAVE, () => this._mouseOverMessage = false, true));

// close on mouse move
let bounds: Range;
Expand Down