Skip to content

Commit b86b7f1

Browse files
author
Rachel Macfarlane
authored
Group decorations by line before rendering
1 parent 99ebdaa commit b86b7f1

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

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

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -737,50 +737,64 @@ export class Minimap extends ViewPart {
737737
const lineHeightRatio = renderMinimap === RenderMinimap.LargeBlocks || renderMinimap === RenderMinimap.SmallBlocks ? 0.5 : 1;
738738
const height = lineHeight * lineHeightRatio;
739739

740-
for (let i = 0; i < decorations.length; i++) {
741-
if (decorations[i].options.minimap) {
742-
this.renderDecoration(canvasContext, decorations[i], layout, height, lineHeight, tabSize, characterWidth);
740+
// Loop over decorations, ignoring those that don't have the minimap property set and rendering those on the same line together
741+
let i = 0;
742+
for (; i < decorations.length; i++) {
743+
if (!decorations[i].options.minimap) {
744+
continue;
743745
}
746+
747+
let decorationsForLine = [decorations[i]];
748+
let currentLine = decorations[i].range.startLineNumber;
749+
let j = i + 1;
750+
while (j < decorations.length && decorations[j].range.startLineNumber === currentLine) {
751+
if (decorations[j].options.minimap) {
752+
decorationsForLine.push(decorations[j]);
753+
}
754+
755+
j += 1;
756+
}
757+
758+
i = j - 1;
759+
this.renderDecorationsForLine(canvasContext, decorationsForLine, layout, currentLine, height, lineHeight, tabSize, characterWidth);
744760
}
745761
}
746762
}
747763

748-
private renderDecoration(canvasContext: CanvasRenderingContext2D,
749-
decoration: ViewModelDecoration,
764+
private renderDecorationsForLine(canvasContext: CanvasRenderingContext2D,
765+
decorations: ViewModelDecoration[],
750766
layout: MinimapLayout,
767+
startLineNumber: number,
751768
height: number,
752769
lineHeight: number,
753770
tabSize: number,
754771
charWidth: number) {
755-
const { startLineNumber, startColumn, endColumn } = decoration.range;
756-
757-
const startIndex = startColumn - 1;
758-
const endIndex = endColumn - 1;
759-
760772
const y = (startLineNumber - layout.startLineNumber) * lineHeight;
761773

762-
// Get the offset of the decoration in the line. Have to read line data to see how much space each character takes.
763-
let x = 0;
764-
let endPosition = 0;
765774
const lineData = this._context.model.getLineContent(startLineNumber);
766-
for (let i = 0; i < endIndex; i++) {
767-
const charCode = lineData.charCodeAt(i);
775+
const lineIndexToXOffset = [0];
776+
for (let i = 1; i < lineData.length + 1; i++) {
777+
const charCode = lineData.charCodeAt(i - 1);
768778
const dx = charCode === CharCode.Tab
769779
? tabSize * charWidth
770780
: strings.isFullWidthCharacter(charCode)
771781
? 2 * charWidth
772782
: charWidth;
773783

774-
if (i < startIndex) {
775-
x += dx;
776-
}
777-
778-
endPosition += dx;
784+
lineIndexToXOffset[i] = lineIndexToXOffset[i - 1] + dx;
779785
}
780786

781-
const width = endPosition - x;
787+
for (let i = 0; i < decorations.length; i++) {
788+
const currentDecoration = decorations[i];
789+
const { startColumn, endColumn } = currentDecoration.range;
790+
const x = lineIndexToXOffset[startColumn - 1];
791+
const width = lineIndexToXOffset[endColumn - 1] - x;
792+
793+
this.renderADecoration(canvasContext, <ModelDecorationMinimapOptions>currentDecoration.options.minimap, x, y, width, height);
794+
}
795+
}
782796

783-
const minimapOptions = <ModelDecorationMinimapOptions>decoration.options.minimap;
797+
private renderADecoration(canvasContext: CanvasRenderingContext2D, minimapOptions: ModelDecorationMinimapOptions, x: number, y: number, width: number, height: number) {
784798
const decorationColor = minimapOptions.getColor(this._context.theme);
785799

786800
canvasContext.fillStyle = decorationColor;

0 commit comments

Comments
 (0)