From 7fddf0f134228020d1d4979f515747373ff9354f Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 4 Mar 2020 17:38:32 +0100 Subject: [PATCH] line decorations for first and last line --- .../viewParts/linesDecorations/linesDecorations.ts | 14 +++++++++++--- src/vs/editor/common/model.ts | 8 ++++++++ src/vs/editor/common/model/textModel.ts | 4 ++++ .../editor/contrib/folding/foldingDecorations.ts | 10 +++++++--- src/vs/monaco.d.ts | 8 ++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts index fc6a255eb83..ba966e913ec 100644 --- a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts +++ b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts @@ -74,9 +74,17 @@ export class LinesDecorationsOverlay extends DedupOverlay { let r: DecorationToRender[] = [], rLen = 0; for (let i = 0, len = decorations.length; i < len; i++) { const d = decorations[i]; - const linesDecorationsClassName = d.options.linesDecorationsClassName; - if (linesDecorationsClassName) { - r[rLen++] = new DecorationToRender(d.range.startLineNumber, d.range.endLineNumber, linesDecorationsClassName); + const linesDecorations = d.options.linesDecorationsClassName; + if (linesDecorations) { + r[rLen++] = new DecorationToRender(d.range.startLineNumber, d.range.endLineNumber, linesDecorations); + } + const firstLineDecorationsClassName = d.options.firstLineDecorationsClassName; + if (firstLineDecorationsClassName) { + r[rLen++] = new DecorationToRender(d.range.startLineNumber, d.range.startLineNumber, firstLineDecorationsClassName); + } + const lastLineDecorationsClassName = d.options.lastLineDecorationsClassName; + if (lastLineDecorationsClassName) { + r[rLen++] = new DecorationToRender(d.range.endLineNumber, d.range.endLineNumber, lastLineDecorationsClassName); } } return r; diff --git a/src/vs/editor/common/model.ts b/src/vs/editor/common/model.ts index 2bf83cca827..65dce0c3d2a 100644 --- a/src/vs/editor/common/model.ts +++ b/src/vs/editor/common/model.ts @@ -123,6 +123,14 @@ export interface IModelDecorationOptions { * If set, the decoration will be rendered in the lines decorations with this CSS class name. */ linesDecorationsClassName?: string | null; + /** + * If set, the decoration will be rendered for first line of the range in the lines decorations with this CSS class name. + */ + firstLineDecorationsClassName?: string | null; + /** + * If set, the decoration will be rendered for last line of the range in the lines decorations for last line with this CSS class name. + */ + lastLineDecorationsClassName?: string | null; /** * If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name. */ diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index 89050a1e6de..e9c4c6f9ecf 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -3053,6 +3053,8 @@ export class ModelDecorationOptions implements model.IModelDecorationOptions { readonly minimap: ModelDecorationMinimapOptions | null; readonly glyphMarginClassName: string | null; readonly linesDecorationsClassName: string | null; + readonly firstLineDecorationsClassName: string | null; + readonly lastLineDecorationsClassName: string | null; readonly marginClassName: string | null; readonly inlineClassName: string | null; readonly inlineClassNameAffectsLetterSpacing: boolean; @@ -3072,6 +3074,8 @@ export class ModelDecorationOptions implements model.IModelDecorationOptions { this.minimap = options.minimap ? new ModelDecorationMinimapOptions(options.minimap) : null; this.glyphMarginClassName = options.glyphMarginClassName ? cleanClassName(options.glyphMarginClassName) : null; this.linesDecorationsClassName = options.linesDecorationsClassName ? cleanClassName(options.linesDecorationsClassName) : null; + this.firstLineDecorationsClassName = options.firstLineDecorationsClassName ? cleanClassName(options.firstLineDecorationsClassName) : null; + this.lastLineDecorationsClassName = options.lastLineDecorationsClassName ? cleanClassName(options.lastLineDecorationsClassName) : null; this.marginClassName = options.marginClassName ? cleanClassName(options.marginClassName) : null; this.inlineClassName = options.inlineClassName ? cleanClassName(options.inlineClassName) : null; this.inlineClassNameAffectsLetterSpacing = options.inlineClassNameAffectsLetterSpacing || false; diff --git a/src/vs/editor/contrib/folding/foldingDecorations.ts b/src/vs/editor/contrib/folding/foldingDecorations.ts index d2ff2bca5b1..1d18885bde5 100644 --- a/src/vs/editor/contrib/folding/foldingDecorations.ts +++ b/src/vs/editor/contrib/folding/foldingDecorations.ts @@ -13,7 +13,8 @@ export class FoldingDecorationProvider implements IDecorationProvider { private static readonly COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, afterContentClassName: 'inline-folded', - linesDecorationsClassName: 'codicon codicon-chevron-right' + isWholeLine: true, + firstLineDecorationsClassName: 'codicon codicon-chevron-right' }); private static readonly COLLAPSED_HIGHLIGHTED_VISUAL_DECORATION = ModelDecorationOptions.register({ @@ -21,16 +22,19 @@ export class FoldingDecorationProvider implements IDecorationProvider { afterContentClassName: 'inline-folded', className: 'folded-background', isWholeLine: true, - linesDecorationsClassName: 'codicon codicon-chevron-right' + firstLineDecorationsClassName: 'codicon codicon-chevron-right' }); private static readonly EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, - linesDecorationsClassName: 'codicon codicon-chevron-down' + isWholeLine: true, + firstLineDecorationsClassName: 'codicon codicon-chevron-down' }); private static readonly EXPANDED_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, + isWholeLine: true, + firstLineDecorationsClassName: 'codicon codicon-chevron-down alwaysShowFoldIcons' }); private static readonly HIDDEN_RANGE_DECORATION = ModelDecorationOptions.register({ diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index ccdfcfcece0..12d6f386692 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -1369,6 +1369,14 @@ declare namespace monaco.editor { * If set, the decoration will be rendered in the lines decorations with this CSS class name. */ linesDecorationsClassName?: string | null; + /** + * If set, the decoration will be rendered for first line of the range in the lines decorations with this CSS class name. + */ + firstLineDecorationsClassName?: string | null; + /** + * If set, the decoration will be rendered for last line of the range in the lines decorations for last line with this CSS class name. + */ + lastLineDecorationsClassName?: string | null; /** * If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name. */ -- GitLab