Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Don't ignore the indent settings in advanced wrapping mode #134171

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/vs/editor/browser/view/domLineBreaksComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
}

const overallWidth = Math.round(firstLineBreakColumn * fontInfo.typicalHalfwidthCharacterWidth);

// Cannot respect WrappingIndent.Indent and WrappingIndent.DeepIndent because that would require
// two dom layouts, in order to first set the width of the first line, and then set the width of the wrapped lines
if (wrappingIndent === WrappingIndent.Indent || wrappingIndent === WrappingIndent.DeepIndent) {
wrappingIndent = WrappingIndent.Same;
}
const additionalIndent = (wrappingIndent === WrappingIndent.DeepIndent ? 2 : wrappingIndent === WrappingIndent.Indent ? 1 : 0);
const additionalIndentSize = Math.round(tabSize * additionalIndent);
const additionalIndentLength = Math.ceil(fontInfo.spaceWidth * additionalIndentSize);

const containerDomNode = document.createElement('div');
Configuration.applyFontInfoSlow(containerDomNode, fontInfo);
Expand Down Expand Up @@ -123,7 +120,7 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
}

const renderLineContent = lineContent.substr(firstNonWhitespaceIndex);
const tmp = renderLine(renderLineContent, wrappedTextIndentLength, tabSize, width, sb);
const tmp = renderLine(renderLineContent, wrappedTextIndentLength, tabSize, width, sb, additionalIndentLength);
firstNonWhitespaceIndices[i] = firstNonWhitespaceIndex;
wrappedTextIndentLengths[i] = wrappedTextIndentLength;
renderLineContents[i] = renderLineContent;
Expand Down Expand Up @@ -152,7 +149,7 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
}

const firstNonWhitespaceIndex = firstNonWhitespaceIndices[i];
const wrappedTextIndentLength = wrappedTextIndentLengths[i];
const wrappedTextIndentLength = wrappedTextIndentLengths[i] + additionalIndentSize;
const visibleColumns = allVisibleColumns[i];

const breakOffsetsVisibleColumn: number[] = [];
Expand Down Expand Up @@ -189,8 +186,18 @@ const enum Constants {
SPAN_MODULO_LIMIT = 16384
}

function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: IStringBuilder): [number[], number[]] {
sb.appendASCIIString('<div style="width:');
function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: IStringBuilder, wrappingIndentLength: number): [number[], number[]] {

if (wrappingIndentLength !== 0) {
let hangingOffset = String(wrappingIndentLength);
sb.appendASCIIString('<div style="text-indent: -');
sb.appendASCIIString(hangingOffset);
sb.appendASCIIString('px; padding-left: ');
sb.appendASCIIString(hangingOffset);
sb.appendASCIIString('px; box-sizing: border-box; width:');
} else {
sb.appendASCIIString('<div style="width:');
}
sb.appendASCIIString(String(width));
sb.appendASCIIString('px;">');
// if (containsRTL) {
Expand Down