Skip to content

Commit 5b70b99

Browse files
committed
Reduce duplication
1 parent eb0fb33 commit 5b70b99

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ export abstract class AbstractLineHighlightOverlay extends DynamicViewOverlay {
155155
return this._renderData[lineIndex];
156156
}
157157

158+
protected _shouldRenderInMargin(): boolean {
159+
return (
160+
(this._renderLineHighlight === 'gutter' || this._renderLineHighlight === 'all')
161+
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
162+
);
163+
}
164+
165+
protected _shouldRenderInContent(): boolean {
166+
return (
167+
(this._renderLineHighlight === 'line' || this._renderLineHighlight === 'all')
168+
&& this._selectionIsEmpty
169+
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
170+
);
171+
}
172+
158173
protected abstract _shouldRenderThis(): boolean;
159174
protected abstract _shouldRenderOther(): boolean;
160175
protected abstract _renderOne(ctx: RenderingContext): string;
@@ -167,40 +182,23 @@ export class CurrentLineHighlightOverlay extends AbstractLineHighlightOverlay {
167182
return `<div class="${className}" style="width:${Math.max(ctx.scrollWidth, this._contentWidth)}px; height:${this._lineHeight}px;"></div>`;
168183
}
169184
protected _shouldRenderThis(): boolean {
170-
return (
171-
(this._renderLineHighlight === 'line' || this._renderLineHighlight === 'all')
172-
&& this._selectionIsEmpty
173-
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
174-
);
185+
return this._shouldRenderInContent();
175186
}
176187
protected _shouldRenderOther(): boolean {
177-
return (
178-
(this._renderLineHighlight === 'gutter' || this._renderLineHighlight === 'all')
179-
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
180-
);
188+
return this._shouldRenderInMargin();
181189
}
182190
}
183191

184192
export class CurrentLineMarginHighlightOverlay extends AbstractLineHighlightOverlay {
185193
protected _renderOne(ctx: RenderingContext): string {
186-
const className = 'current-line' + (this._shouldRenderMargin() ? ' current-line-margin' : '') + (this._shouldRenderOther() ? ' current-line-margin-both' : '');
194+
const className = 'current-line' + (this._shouldRenderInMargin() ? ' current-line-margin' : '') + (this._shouldRenderOther() ? ' current-line-margin-both' : '');
187195
return `<div class="${className}" style="width:${this._contentLeft}px; height:${this._lineHeight}px;"></div>`;
188196
}
189-
protected _shouldRenderMargin(): boolean {
190-
return (
191-
(this._renderLineHighlight === 'gutter' || this._renderLineHighlight === 'all')
192-
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
193-
);
194-
}
195197
protected _shouldRenderThis(): boolean {
196198
return true;
197199
}
198200
protected _shouldRenderOther(): boolean {
199-
return (
200-
(this._renderLineHighlight === 'line' || this._renderLineHighlight === 'all')
201-
&& this._selectionIsEmpty
202-
&& (!this._renderLineHighlightOnlyWhenFocus || this._focused)
203-
);
201+
return this._shouldRenderInContent();
204202
}
205203
}
206204

0 commit comments

Comments
 (0)