File tree Expand file tree Collapse file tree 6 files changed +31
-21
lines changed Expand file tree Collapse file tree 6 files changed +31
-21
lines changed Original file line number Diff line number Diff line change 1
1
@import " ~@code-hike/mini-frame/dist/index.scss" ;
2
2
@import " ~@code-hike/mini-terminal/dist/index.scss" ;
3
+ @import " ~@code-hike/smooth-code/dist/index.scss" ;
3
4
4
5
/* * tabs */
5
6
Original file line number Diff line number Diff line change
1
+ .ch-code-line-number {
2
+ user-select : none ;
3
+ text-align : right ;
4
+ display : inline-block ;
5
+ box-sizing : border-box ;
6
+ padding-right : 1.5ch ;
7
+ font-variant-numeric : tabular-nums ;
8
+ }
Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ export function SmoothContainer({
54
54
55
55
const lineNumberPad =
56
56
( dimensions ?. lineNumberWidth || 0 ) * zoom
57
- const leftPad = 16 + lineNumberPad
57
+
58
+ const leftPad = lineNumberPad || 16
58
59
59
60
const width = Math . max (
60
61
focusWidth + leftPad ,
@@ -221,10 +222,14 @@ function getContentProps({
221
222
} = dimensions !
222
223
const originalFocusHeight =
223
224
( extremes [ 1 ] - extremes [ 0 ] + 3 ) * lineHeight
225
+
226
+ const leftPadding = dimensions ?. lineNumberWidth || 16
227
+ const rightPadding = 16
228
+
224
229
const zoom = Math . max (
225
230
Math . min (
226
- // TODO consider line number width
227
- ( containerWidth - 16 * 2 ) / lineWidth ,
231
+ ( containerWidth - leftPadding - rightPadding ) /
232
+ lineWidth ,
228
233
containerHeight / originalFocusHeight ,
229
234
maxZoom
230
235
) ,
Original file line number Diff line number Diff line change @@ -159,21 +159,16 @@ function LineGroup({
159
159
< React . Fragment key = { key } >
160
160
{ lineNumberWidth ? (
161
161
< span
162
+ className = "ch-code-line-number"
162
163
style = { {
164
+ position : "absolute" ,
163
165
top : 0 ,
164
166
left : 0 ,
165
167
transform : `translate(${
166
168
dx * focusWidth
167
169
} px, ${ ( dy - startY ) * lineHeight } px)`,
168
- position : "absolute" ,
169
- userSelect : "none" ,
170
170
width : lineNumberWidth ,
171
- textAlign : "right" ,
172
- display : "inline-block" ,
173
- boxSizing : "border-box" ,
174
- paddingRight : "1ch" ,
175
171
opacity,
176
- fontVariantNumeric : "tabular-nums" ,
177
172
color : getColor (
178
173
theme ,
179
174
ColorName . LineNumberForeground
Original file line number Diff line number Diff line change @@ -79,14 +79,11 @@ function useDimensions(
79
79
}
80
80
key = { i }
81
81
>
82
- < span
83
- style = { {
84
- display : "inline-block" ,
85
- width : lineNumbers ? "auto" : 0 ,
86
- } }
87
- >
88
- { lineCount } 0
89
- </ span >
82
+ { lineNumbers ? (
83
+ < span className = "ch-code-line-number" >
84
+ _{ lineCount }
85
+ </ span >
86
+ ) : undefined }
90
87
< div style = { { display : "inline-block" } } >
91
88
< span > { line } </ span >
92
89
</ div >
@@ -119,7 +116,9 @@ function useDimensions(
119
116
const lineNumberSpan = pll ?. querySelector (
120
117
":scope > span"
121
118
) as HTMLElement
122
- const lnw = getWidthWithoutPadding ( lineNumberSpan )
119
+ const lnw = lineNumberSpan
120
+ ? getWidthWithPadding ( lineNumberSpan )
121
+ : 0
123
122
124
123
const plw = getWidthWithoutPadding ( lineContentDiv )
125
124
const colWidth = plw / prevLongestLine . length || 1
@@ -195,6 +194,10 @@ function getWidthWithoutPadding(element: HTMLElement) {
195
194
parseFloat ( computedStyle . paddingRight )
196
195
)
197
196
}
197
+ function getWidthWithPadding ( element : HTMLElement ) {
198
+ const computedStyle = getComputedStyle ( element )
199
+ return parseFloat ( computedStyle . width )
200
+ }
198
201
function getHeightWithoutPadding (
199
202
element : HTMLElement | null
200
203
) {
Original file line number Diff line number Diff line change @@ -65,8 +65,6 @@ const x = (y) => y++ * foobarbaz
65
65
)
66
66
} , [ ] )
67
67
68
- console . log ( { tween } )
69
-
70
68
return (
71
69
< WithProgress >
72
70
{ progress => (
You can’t perform that action at this time.
0 commit comments