Skip to content

Commit d578207

Browse files
authored
Merge pull request microsoft#134171 from byteit101/wrapping-fixes
Fix: Don't ignore the indent settings in advanced wrapping mode
2 parents 9264622 + bc4945e commit d578207

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/vs/editor/browser/view/domLineBreaksComputer.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
6969
}
7070

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

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

125122
const renderLineContent = lineContent.substr(firstNonWhitespaceIndex);
126-
const tmp = renderLine(renderLineContent, wrappedTextIndentLength, tabSize, width, sb);
123+
const tmp = renderLine(renderLineContent, wrappedTextIndentLength, tabSize, width, sb, additionalIndentLength);
127124
firstNonWhitespaceIndices[i] = firstNonWhitespaceIndex;
128125
wrappedTextIndentLengths[i] = wrappedTextIndentLength;
129126
renderLineContents[i] = renderLineContent;
@@ -152,7 +149,7 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
152149
}
153150

154151
const firstNonWhitespaceIndex = firstNonWhitespaceIndices[i];
155-
const wrappedTextIndentLength = wrappedTextIndentLengths[i];
152+
const wrappedTextIndentLength = wrappedTextIndentLengths[i] + additionalIndentSize;
156153
const visibleColumns = allVisibleColumns[i];
157154

158155
const breakOffsetsVisibleColumn: number[] = [];
@@ -189,8 +186,18 @@ const enum Constants {
189186
SPAN_MODULO_LIMIT = 16384
190187
}
191188

192-
function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: IStringBuilder): [number[], number[]] {
193-
sb.appendASCIIString('<div style="width:');
189+
function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: IStringBuilder, wrappingIndentLength: number): [number[], number[]] {
190+
191+
if (wrappingIndentLength !== 0) {
192+
let hangingOffset = String(wrappingIndentLength);
193+
sb.appendASCIIString('<div style="text-indent: -');
194+
sb.appendASCIIString(hangingOffset);
195+
sb.appendASCIIString('px; padding-left: ');
196+
sb.appendASCIIString(hangingOffset);
197+
sb.appendASCIIString('px; box-sizing: border-box; width:');
198+
} else {
199+
sb.appendASCIIString('<div style="width:');
200+
}
194201
sb.appendASCIIString(String(width));
195202
sb.appendASCIIString('px;">');
196203
// if (containsRTL) {

0 commit comments

Comments
 (0)