Skip to content

Commit 271026e

Browse files
Eric Amodioeamodio
Eric Amodio
authored andcommitted
Avoids paragraphs for newlines in string tooltips
This better matches the native tooltip styling of newlines
1 parent a5dfd9d commit 271026e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/vs/base/browser/ui/iconLabel/iconLabel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ export class IconLabel extends Disposable {
210210
};
211211
const resolvedTooltip = await tooltip;
212212
if (resolvedTooltip) {
213-
hoverOptions = { text: resolvedTooltip, target, anchorPosition: AnchorPosition.BELOW };
213+
hoverOptions = {
214+
text: resolvedTooltip,
215+
target,
216+
anchorPosition: AnchorPosition.BELOW
217+
};
214218
}
215219
}
216220
if (hoverOptions) {

src/vs/base/common/htmlContent.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export interface IMarkdownString {
1515
uris?: { [href: string]: UriComponents };
1616
}
1717

18+
export const enum MarkdownStringTextNewlineStyle {
19+
Paragraph = 0,
20+
Break = 1,
21+
}
22+
1823
export class MarkdownString implements IMarkdownString {
1924
private readonly _isTrusted: boolean;
2025
private readonly _supportThemeIcons: boolean;
@@ -41,11 +46,11 @@ export class MarkdownString implements IMarkdownString {
4146
get isTrusted() { return this._isTrusted; }
4247
get supportThemeIcons() { return this._supportThemeIcons; }
4348

44-
appendText(value: string): MarkdownString {
49+
appendText(value: string, newlineStyle: MarkdownStringTextNewlineStyle = MarkdownStringTextNewlineStyle.Paragraph): MarkdownString {
4550
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
4651
this._value += (this._supportThemeIcons ? escapeCodicons(value) : value)
4752
.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
48-
.replace(/\n/g, '\n\n');
53+
.replace(/\n/g, newlineStyle === MarkdownStringTextNewlineStyle.Break ? '\\\n' : '\n\n');
4954

5055
return this;
5156
}

src/vs/workbench/services/hover/browser/hoverWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Widget } from 'vs/base/browser/ui/widget';
1616
import { AnchorPosition } from 'vs/base/browser/ui/contextview/contextview';
1717
import { IOpenerService } from 'vs/platform/opener/common/opener';
1818
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
19-
import { MarkdownString } from 'vs/base/common/htmlContent';
19+
import { MarkdownString, MarkdownStringTextNewlineStyle } from 'vs/base/common/htmlContent';
2020
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2121
import { MarkdownRenderer } from 'vs/editor/browser/core/markdownRenderer';
2222

@@ -82,7 +82,7 @@ export class HoverWidget extends Widget {
8282

8383
const rowElement = $('div.hover-row.markdown-hover');
8484
const contentsElement = $('div.hover-contents');
85-
const markdown = typeof options.text === 'string' ? new MarkdownString().appendText(options.text) : options.text;
85+
const markdown = typeof options.text === 'string' ? new MarkdownString().appendText(options.text, MarkdownStringTextNewlineStyle.Break) : options.text;
8686

8787
const mdRenderer = this._instantiationService.createInstance(
8888
MarkdownRenderer,

0 commit comments

Comments
 (0)