Skip to content

Commit a0de9e5

Browse files
authored
Refactoring the code (microsoft#210483)
refactoring the code
1 parent 180b5b6 commit a0de9e5

File tree

3 files changed

+79
-71
lines changed

3 files changed

+79
-71
lines changed

src/vs/editor/contrib/hover/browser/hoverController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config
1212
import { Range } from 'vs/editor/common/core/range';
1313
import { IEditorContribution, IScrollEvent } from 'vs/editor/common/editorCommon';
1414
import { HoverStartMode, HoverStartSource } from 'vs/editor/contrib/hover/browser/hoverOperation';
15-
import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHover';
1615
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1716
import { IHoverWidget } from 'vs/editor/contrib/hover/browser/hoverTypes';
1817
import { InlineSuggestionHintsContentWidget } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsHintsWidget';
@@ -22,6 +21,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
2221
import { ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHoverWidget';
2322
import { ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHoverController';
2423
import 'vs/css!./hover';
24+
import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHoverWidget';
2525

2626
// sticky hover widget which doesn't disappear on focus out and such
2727
const _sticky = false
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { asArray } from 'vs/base/common/arrays';
7+
import { IMarkdownString, isEmptyMarkdownString } from 'vs/base/common/htmlContent';
8+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
9+
import { IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation';
10+
import { GlyphMarginLane } from 'vs/editor/common/model';
11+
12+
export type LaneOrLineNumber = GlyphMarginLane | 'lineNo';
13+
14+
export interface IHoverMessage {
15+
value: IMarkdownString;
16+
}
17+
18+
export class MarginHoverComputer implements IHoverComputer<IHoverMessage> {
19+
20+
private _lineNumber: number = -1;
21+
private _laneOrLine: LaneOrLineNumber = GlyphMarginLane.Center;
22+
23+
public get lineNumber(): number {
24+
return this._lineNumber;
25+
}
26+
27+
public set lineNumber(value: number) {
28+
this._lineNumber = value;
29+
}
30+
31+
public get lane(): LaneOrLineNumber {
32+
return this._laneOrLine;
33+
}
34+
35+
public set lane(value: LaneOrLineNumber) {
36+
this._laneOrLine = value;
37+
}
38+
39+
constructor(
40+
private readonly _editor: ICodeEditor
41+
) {
42+
}
43+
44+
public computeSync(): IHoverMessage[] {
45+
46+
const toHoverMessage = (contents: IMarkdownString): IHoverMessage => {
47+
return {
48+
value: contents
49+
};
50+
};
51+
52+
const lineDecorations = this._editor.getLineDecorations(this._lineNumber);
53+
54+
const result: IHoverMessage[] = [];
55+
const isLineHover = this._laneOrLine === 'lineNo';
56+
if (!lineDecorations) {
57+
return result;
58+
}
59+
60+
for (const d of lineDecorations) {
61+
const lane = d.options.glyphMargin?.position ?? GlyphMarginLane.Center;
62+
if (!isLineHover && lane !== this._laneOrLine) {
63+
continue;
64+
}
65+
66+
const hoverMessage = isLineHover ? d.options.lineNumberHoverMessage : d.options.glyphMarginHoverMessage;
67+
if (!hoverMessage || isEmptyMarkdownString(hoverMessage)) {
68+
continue;
69+
}
70+
71+
result.push(...asArray(hoverMessage).map(toHoverMessage));
72+
}
73+
74+
return result;
75+
}
76+
}

src/vs/editor/contrib/hover/browser/marginHover.ts renamed to src/vs/editor/contrib/hover/browser/marginHoverWidget.ts

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as dom from 'vs/base/browser/dom';
7-
import { asArray } from 'vs/base/common/arrays';
8-
import { IMarkdownString, isEmptyMarkdownString } from 'vs/base/common/htmlContent';
97
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
108
import { MarkdownRenderer } from 'vs/editor/browser/widget/markdownRenderer/browser/markdownRenderer';
119
import { ICodeEditor, IEditorMouseEvent, IOverlayWidget, IOverlayWidgetPosition, MouseTargetType } from 'vs/editor/browser/editorBrowser';
1210
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
1311
import { ILanguageService } from 'vs/editor/common/languages/language';
14-
import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation';
12+
import { HoverOperation, HoverStartMode } from 'vs/editor/contrib/hover/browser/hoverOperation';
1513
import { IOpenerService } from 'vs/platform/opener/common/opener';
1614
import { HoverWidget } from 'vs/base/browser/ui/hover/hoverWidget';
17-
import { GlyphMarginLane } from 'vs/editor/common/model';
1815
import { IHoverWidget } from 'vs/editor/contrib/hover/browser/hoverTypes';
16+
import { IHoverMessage, LaneOrLineNumber, MarginHoverComputer } from 'vs/editor/contrib/hover/browser/marginHoverComputer';
1917

2018
const $ = dom.$;
2119

22-
export interface IHoverMessage {
23-
value: IMarkdownString;
24-
}
25-
26-
type LaneOrLineNumber = GlyphMarginLane | 'lineNo';
27-
2820
export class MarginHoverWidget extends Disposable implements IOverlayWidget, IHoverWidget {
2921

3022
public static readonly ID = 'editor.contrib.modesGlyphHoverWidget';
@@ -190,63 +182,3 @@ export class MarginHoverWidget extends Disposable implements IOverlayWidget, IHo
190182
this._hover.containerDomNode.style.top = `${Math.max(Math.round(top), 0)}px`;
191183
}
192184
}
193-
194-
class MarginHoverComputer implements IHoverComputer<IHoverMessage> {
195-
196-
private _lineNumber: number = -1;
197-
private _laneOrLine: LaneOrLineNumber = GlyphMarginLane.Center;
198-
199-
public get lineNumber(): number {
200-
return this._lineNumber;
201-
}
202-
203-
public set lineNumber(value: number) {
204-
this._lineNumber = value;
205-
}
206-
207-
public get lane(): LaneOrLineNumber {
208-
return this._laneOrLine;
209-
}
210-
211-
public set lane(value: LaneOrLineNumber) {
212-
this._laneOrLine = value;
213-
}
214-
215-
constructor(
216-
private readonly _editor: ICodeEditor
217-
) {
218-
}
219-
220-
public computeSync(): IHoverMessage[] {
221-
222-
const toHoverMessage = (contents: IMarkdownString): IHoverMessage => {
223-
return {
224-
value: contents
225-
};
226-
};
227-
228-
const lineDecorations = this._editor.getLineDecorations(this._lineNumber);
229-
230-
const result: IHoverMessage[] = [];
231-
const isLineHover = this._laneOrLine === 'lineNo';
232-
if (!lineDecorations) {
233-
return result;
234-
}
235-
236-
for (const d of lineDecorations) {
237-
const lane = d.options.glyphMargin?.position ?? GlyphMarginLane.Center;
238-
if (!isLineHover && lane !== this._laneOrLine) {
239-
continue;
240-
}
241-
242-
const hoverMessage = isLineHover ? d.options.lineNumberHoverMessage : d.options.glyphMarginHoverMessage;
243-
if (!hoverMessage || isEmptyMarkdownString(hoverMessage)) {
244-
continue;
245-
}
246-
247-
result.push(...asArray(hoverMessage).map(toHoverMessage));
248-
}
249-
250-
return result;
251-
}
252-
}

0 commit comments

Comments
 (0)