Skip to content

Commit 25d0d37

Browse files
Fix scrollbar appearing on tree nodes with code
This commit addresses unexpected horizontal scrollbars appearing in tree nodes due to incorrect padding calculations for inline code elements. The issue occurs when vertical padding pushes content beyond the node boundaries. The solution: - Simplify x-padding calculation by removing unnecessary font-size math - Calculate y-padding using line-height (lh) units for better scaling - Change code elements to inline-block for proper vertical alignment
1 parent 2f2813e commit 25d0d37

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

src/presentation/assets/styles/base/_code-styling.scss

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@use "@/presentation/assets/styles/mixins" as *;
33
@use "@/presentation/assets/styles/vite-path" as *;
44
@use "@/presentation/assets/styles/typography" as *;
5-
@use 'sass:math';
65

76
@mixin code-block() {
87
pre {
@@ -26,31 +25,71 @@
2625
$color-background,
2726
$code-block-padding,
2827
) {
29-
$font-size-code: $font-size-relative-smaller; // Keep relative size to scale right with different text sizes around.
28+
$font-size-code-in-percentage: $font-size-relative-smaller; // Keep relative size to scale right with different text sizes around.
3029
$border-radius: 2px; // Subtle rounding still maintaining sharp design.
3130

3231
@include base-code {
3332
font-family: $font-family-monospace;
34-
border-radius: $border-radius;
35-
font-size: $font-size-code;
33+
font-size: $font-size-code-in-percentage;
3634
color: $color-on-primary;
3735
}
3836

3937
@include inline-code {
4038
background: $color-background;
4139
word-break: break-all; // Enables inline code to wrap with the text, even for long single words (like registry paths), thus preventing overflow.
4240

43-
$font-size-code-in-decimal: math.div($font-size-code, 100%); // Converts percentage (e.g., 85%) to decimal (e.g., 0.85) for calculations.
44-
$font-size-code-in-em: calc(1em * #{$font-size-code-in-decimal});
45-
$vertical-padding: calc((1em - #{$font-size-code-in-em}) / 2);
46-
$horizontal-padding: calc(#{$font-size-code-in-em} * 0.4);
47-
padding: $vertical-padding $horizontal-padding;
41+
$padding-x-max : 8px;
42+
$padding-x-desired : 0.4em;
43+
$padding-y-max : 4px;
44+
$padding-y-desired : calculate-min-vertical-empty-space($font-size-code-in-percentage);
45+
$padding-y-desired : calc(calculate-min-vertical-empty-space($font-size-code-in-percentage) / 2);
46+
47+
$padding-y: min($padding-y-desired, $padding-y-max);
48+
$padding-x: min($padding-x-desired, $padding-x-max);
49+
padding: #{$padding-y} #{$padding-x};
50+
display: inline-block; // Required for centering, otherwise contents align towards bottom with Y padding, causing overflows
4851
}
4952

53+
5054
@include code-block {
5155
background: $color-background;
5256
border-radius: $border-radius;
5357
overflow: auto; // Prevents horizontal expansion of inner content (e.g., when a code block is shown)
5458
padding: $code-block-padding;
5559
}
5660
}
61+
62+
@function convert-percentage-to-decimal-ratio($current-relative-font-size) {
63+
@return calc($current-relative-font-size / 100%);
64+
}
65+
66+
67+
@function calculate-inline-parent-min-line-height(
68+
$inline-child-relative-font-size-in-decimal,
69+
) {
70+
$parent-line-height: calc(
71+
1lh /* self height, height = 1 lh for inline element*/
72+
/
73+
#{$inline-child-relative-font-size-in-decimal} /* minimum possible font size of parent */
74+
);
75+
$parent-min-height: round(down, #{$parent-line-height}, 1px);
76+
@return $parent-min-height;
77+
}
78+
79+
@function calculate-vertical-empty-space($parent-min-line-height) {
80+
$available-space: calc(
81+
#{$parent-min-line-height} /* Parent should be able to show single line of text text */
82+
-
83+
1lh, /* self height, height = 1 lh for inline element*/
84+
);
85+
@return max(#{$available-space}, 0px); // Return 0px if there's no available space
86+
}
87+
88+
@function calculate-min-vertical-empty-space(
89+
$inline-element-relative-font-size-in-percentage,
90+
) {
91+
$self-font-size-relative-in-decimal: convert-percentage-to-decimal-ratio($inline-element-relative-font-size-in-percentage);
92+
$parent-minimum-height: calculate-inline-parent-min-line-height($self-font-size-relative-in-decimal);
93+
$total-empty-space-y: calculate-vertical-empty-space($parent-minimum-height);
94+
@return $total-empty-space-y;
95+
}

0 commit comments

Comments
 (0)