Skip to content

Commit b6b76c9

Browse files
authored
Merge pull request microsoft#146842 from microsoft/alex/stable-99589
Do not render whitespace in tokens that contain RTL text
2 parents efea4cc + 46a5070 commit b6b76c9

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/vs/editor/common/viewLayout/viewLineRenderer.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,18 @@ function _applyRenderWhitespace(input: RenderLineInput, lineContent: string, len
773773
isInWhitespace = lineIsEmptyOrWhitespace || charIndex > lastNonWhitespaceIndex;
774774
}
775775

776+
if (isInWhitespace && tokenContainsRTL) {
777+
// If the token contains RTL text, breaking it up into multiple line parts
778+
// to render whitespace might affect the browser's bidi layout.
779+
//
780+
// We render whitespace in such tokens only if the whitespace
781+
// is the leading or the trailing whitespace of the line,
782+
// which doesn't affect the browser's bidi layout.
783+
if (charIndex >= firstNonWhitespaceIndex && charIndex <= lastNonWhitespaceIndex) {
784+
isInWhitespace = false;
785+
}
786+
}
787+
776788
if (wasInWhitespace) {
777789
// was in whitespace token
778790
if (!isInWhitespace || (!useMonospaceOptimizations && tmpIndent >= tabSize)) {

src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,52 @@ suite('viewLineRenderer.renderLine', () => {
553553
assert.strictEqual(_actual.containsRTL, true);
554554
});
555555

556+
test('issue #99589: Rendering whitespace influences bidi layout', () => {
557+
const lineText = ' [\"🖨️ چاپ فاکتور\",\"🎨 تنظیمات\"]';
558+
559+
const lineParts = createViewLineTokens([
560+
createPart(5, 2),
561+
createPart(21, 3),
562+
createPart(22, 2),
563+
createPart(34, 3),
564+
createPart(35, 2),
565+
]);
566+
567+
const expectedOutput = [
568+
'<span class="mtkw">\u00b7\u00b7\u00b7\u00b7</span>',
569+
'<span class="mtk2">[</span>',
570+
'<span style="unicode-bidi:isolate" class="mtk3">"🖨️\u00a0چاپ\u00a0فاکتور"</span>',
571+
'<span class="mtk2">,</span>',
572+
'<span style="unicode-bidi:isolate" class="mtk3">"🎨\u00a0تنظیمات"</span>',
573+
'<span class="mtk2">]</span>'
574+
].join('');
575+
576+
const _actual = renderViewLine(new RenderLineInput(
577+
true,
578+
true,
579+
lineText,
580+
false,
581+
false,
582+
true,
583+
0,
584+
lineParts,
585+
[],
586+
4,
587+
0,
588+
10,
589+
10,
590+
10,
591+
-1,
592+
'all',
593+
false,
594+
false,
595+
null
596+
));
597+
598+
assert.strictEqual(_actual.html, '<span dir="ltr">' + expectedOutput + '</span>');
599+
assert.strictEqual(_actual.containsRTL, true);
600+
});
601+
556602
test('issue #6885: Splits large tokens', () => {
557603
// 1 1 1
558604
// 1 2 3 4 5 6 7 8 9 0 1 2

0 commit comments

Comments
 (0)