Skip to content

Commit c74e6f5

Browse files
authored
Fix rounding error that was causing #6634 (#7587)
Addresses #6634 by fixing a rounding error in the calculation of `lineNumbersWidth` in `editorOptions.ts`.
1 parent 55dad0b commit c74e6f5

File tree

2 files changed

+156
-10
lines changed

2 files changed

+156
-10
lines changed

src/vs/editor/common/config/editorOptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,10 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
27482748
let lineNumbersWidth = 0;
27492749
if (showLineNumbers) {
27502750
const digitCount = Math.max(lineNumbersDigitCount, lineNumbersMinChars);
2751-
lineNumbersWidth = Math.round(digitCount * maxDigitWidth);
2751+
// --- Start Positron ---
2752+
// Use Math.ceil instead of Math.round. Fixes https://github.com/posit-dev/positron/issues/6634.
2753+
lineNumbersWidth = Math.ceil(digitCount * maxDigitWidth);
2754+
// --- End Positron ---
27522755
}
27532756

27542757
let glyphMarginWidth = 0;

src/vs/editor/test/browser/config/editorLayoutProvider.test.ts

+152-9
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,77 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
731731
});
732732
});
733733

734-
test('EditorLayoutProvider 8 - rounds floats', () => {
734+
// --- Start Positron ---
735+
// test('EditorLayoutProvider 8 - rounds floats', () => {
736+
// doTest({
737+
// outerWidth: 900,
738+
// outerHeight: 900,
739+
// showGlyphMargin: false,
740+
// lineHeight: 16,
741+
// showLineNumbers: true,
742+
// lineNumbersMinChars: 5,
743+
// lineNumbersDigitCount: 6,
744+
// lineDecorationsWidth: 10,
745+
// typicalHalfwidthCharacterWidth: 5.05,
746+
// maxDigitWidth: 5.05,
747+
// verticalScrollbarWidth: 0,
748+
// horizontalScrollbarHeight: 0,
749+
// scrollbarArrowSize: 0,
750+
// verticalScrollbarHasArrows: false,
751+
// minimap: false,
752+
// minimapSide: 'right',
753+
// minimapRenderCharacters: true,
754+
// minimapMaxColumn: 150,
755+
// pixelRatio: 1,
756+
// }, {
757+
// width: 900,
758+
// height: 900,
759+
760+
// glyphMarginLeft: 0,
761+
// glyphMarginWidth: 0,
762+
// glyphMarginDecorationLaneCount: 1,
763+
764+
// lineNumbersLeft: 0,
765+
// lineNumbersWidth: 30,
766+
767+
// decorationsLeft: 30,
768+
// decorationsWidth: 10,
769+
770+
// contentLeft: 40,
771+
// contentWidth: 860,
772+
773+
// minimap: {
774+
// renderMinimap: RenderMinimap.None,
775+
// minimapLeft: 0,
776+
// minimapWidth: 0,
777+
// minimapHeightIsEditorHeight: false,
778+
// minimapIsSampling: false,
779+
// minimapScale: 1,
780+
// minimapLineHeight: 1,
781+
// minimapCanvasInnerWidth: 0,
782+
// minimapCanvasInnerHeight: 900,
783+
// minimapCanvasOuterWidth: 0,
784+
// minimapCanvasOuterHeight: 900,
785+
// },
786+
787+
// viewportColumn: 169,
788+
// isWordWrapMinified: false,
789+
// isViewportWrapping: false,
790+
// wrappingColumn: -1,
791+
792+
// verticalScrollbarWidth: 0,
793+
// horizontalScrollbarHeight: 0,
794+
795+
// overviewRuler: {
796+
// top: 0,
797+
// width: 0,
798+
// height: 900,
799+
// right: 0
800+
// }
801+
// });
802+
// });
803+
804+
test('EditorLayoutProvider 8 - ceil floats', () => {
735805
doTest({
736806
outerWidth: 900,
737807
outerHeight: 900,
@@ -761,13 +831,13 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
761831
glyphMarginDecorationLaneCount: 1,
762832

763833
lineNumbersLeft: 0,
764-
lineNumbersWidth: 30,
834+
lineNumbersWidth: 31,
765835

766-
decorationsLeft: 30,
836+
decorationsLeft: 31,
767837
decorationsWidth: 10,
768838

769-
contentLeft: 40,
770-
contentWidth: 860,
839+
contentLeft: 41,
840+
contentWidth: 859,
771841

772842
minimap: {
773843
renderMinimap: RenderMinimap.None,
@@ -799,6 +869,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
799869
}
800870
});
801871
});
872+
// --- End Positron ---
802873

803874
test('EditorLayoutProvider 9 - render minimap', () => {
804875
doTest({
@@ -1360,6 +1431,77 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
13601431
});
13611432
});
13621433

1434+
// --- Start Positron ---
1435+
// test('issue #31312: When wrapping, leave 2px for the cursor', () => {
1436+
// doTest({
1437+
// outerWidth: 1201,
1438+
// outerHeight: 422,
1439+
// showGlyphMargin: true,
1440+
// lineHeight: 30,
1441+
// showLineNumbers: true,
1442+
// lineNumbersMinChars: 3,
1443+
// lineNumbersDigitCount: 1,
1444+
// lineDecorationsWidth: 26,
1445+
// typicalHalfwidthCharacterWidth: 12.04296875,
1446+
// maxDigitWidth: 12.04296875,
1447+
// verticalScrollbarWidth: 14,
1448+
// horizontalScrollbarHeight: 10,
1449+
// scrollbarArrowSize: 11,
1450+
// verticalScrollbarHasArrows: false,
1451+
// minimap: true,
1452+
// minimapSide: 'right',
1453+
// minimapRenderCharacters: true,
1454+
// minimapMaxColumn: 120,
1455+
// pixelRatio: 2
1456+
// }, {
1457+
// width: 1201,
1458+
// height: 422,
1459+
1460+
// glyphMarginLeft: 0,
1461+
// glyphMarginWidth: 30,
1462+
// glyphMarginDecorationLaneCount: 1,
1463+
1464+
// lineNumbersLeft: 30,
1465+
// lineNumbersWidth: 36,
1466+
1467+
// decorationsLeft: 66,
1468+
// decorationsWidth: 26,
1469+
1470+
// contentLeft: 92,
1471+
// contentWidth: 1018,
1472+
1473+
// minimap: {
1474+
// renderMinimap: RenderMinimap.Text,
1475+
// minimapLeft: 1096,
1476+
// minimapWidth: 91,
1477+
// minimapHeightIsEditorHeight: false,
1478+
// minimapIsSampling: false,
1479+
// minimapScale: 2,
1480+
// minimapLineHeight: 4,
1481+
// minimapCanvasInnerWidth: 182,
1482+
// minimapCanvasInnerHeight: 844,
1483+
// minimapCanvasOuterWidth: 91,
1484+
// minimapCanvasOuterHeight: 422,
1485+
// },
1486+
1487+
// viewportColumn: 83,
1488+
// isWordWrapMinified: false,
1489+
// isViewportWrapping: false,
1490+
// wrappingColumn: -1,
1491+
1492+
// verticalScrollbarWidth: 14,
1493+
// horizontalScrollbarHeight: 10,
1494+
1495+
// overviewRuler: {
1496+
// top: 0,
1497+
// width: 14,
1498+
// height: 422,
1499+
// right: 0
1500+
// }
1501+
// });
1502+
1503+
// });
1504+
13631505
test('issue #31312: When wrapping, leave 2px for the cursor', () => {
13641506
doTest({
13651507
outerWidth: 1201,
@@ -1390,13 +1532,13 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
13901532
glyphMarginDecorationLaneCount: 1,
13911533

13921534
lineNumbersLeft: 30,
1393-
lineNumbersWidth: 36,
1535+
lineNumbersWidth: 37,
13941536

1395-
decorationsLeft: 66,
1537+
decorationsLeft: 67,
13961538
decorationsWidth: 26,
13971539

1398-
contentLeft: 92,
1399-
contentWidth: 1018,
1540+
contentLeft: 93,
1541+
contentWidth: 1017,
14001542

14011543
minimap: {
14021544
renderMinimap: RenderMinimap.Text,
@@ -1429,4 +1571,5 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
14291571
});
14301572

14311573
});
1574+
// --- End Positron ---
14321575
});

0 commit comments

Comments
 (0)