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 11@import " ~@code-hike/mini-frame/dist/index.scss" ;
22@import " ~@code-hike/mini-terminal/dist/index.scss" ;
3+ @import " ~@code-hike/smooth-code/dist/index.scss" ;
34
45/* * tabs */
56
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({
5454
5555 const lineNumberPad =
5656 ( dimensions ?. lineNumberWidth || 0 ) * zoom
57- const leftPad = 16 + lineNumberPad
57+
58+ const leftPad = lineNumberPad || 16
5859
5960 const width = Math . max (
6061 focusWidth + leftPad ,
@@ -221,10 +222,14 @@ function getContentProps({
221222 } = dimensions !
222223 const originalFocusHeight =
223224 ( extremes [ 1 ] - extremes [ 0 ] + 3 ) * lineHeight
225+
226+ const leftPadding = dimensions ?. lineNumberWidth || 16
227+ const rightPadding = 16
228+
224229 const zoom = Math . max (
225230 Math . min (
226- // TODO consider line number width
227- ( containerWidth - 16 * 2 ) / lineWidth ,
231+ ( containerWidth - leftPadding - rightPadding ) /
232+ lineWidth ,
228233 containerHeight / originalFocusHeight ,
229234 maxZoom
230235 ) ,
Original file line number Diff line number Diff line change @@ -159,21 +159,16 @@ function LineGroup({
159159 < React . Fragment key = { key } >
160160 { lineNumberWidth ? (
161161 < span
162+ className = "ch-code-line-number"
162163 style = { {
164+ position : "absolute" ,
163165 top : 0 ,
164166 left : 0 ,
165167 transform : `translate(${
166168 dx * focusWidth
167169 } px, ${ ( dy - startY ) * lineHeight } px)`,
168- position : "absolute" ,
169- userSelect : "none" ,
170170 width : lineNumberWidth ,
171- textAlign : "right" ,
172- display : "inline-block" ,
173- boxSizing : "border-box" ,
174- paddingRight : "1ch" ,
175171 opacity,
176- fontVariantNumeric : "tabular-nums" ,
177172 color : getColor (
178173 theme ,
179174 ColorName . LineNumberForeground
Original file line number Diff line number Diff line change @@ -79,14 +79,11 @@ function useDimensions(
7979 }
8080 key = { i }
8181 >
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 }
9087 < div style = { { display : "inline-block" } } >
9188 < span > { line } </ span >
9289 </ div >
@@ -119,7 +116,9 @@ function useDimensions(
119116 const lineNumberSpan = pll ?. querySelector (
120117 ":scope > span"
121118 ) as HTMLElement
122- const lnw = getWidthWithoutPadding ( lineNumberSpan )
119+ const lnw = lineNumberSpan
120+ ? getWidthWithPadding ( lineNumberSpan )
121+ : 0
123122
124123 const plw = getWidthWithoutPadding ( lineContentDiv )
125124 const colWidth = plw / prevLongestLine . length || 1
@@ -195,6 +194,10 @@ function getWidthWithoutPadding(element: HTMLElement) {
195194 parseFloat ( computedStyle . paddingRight )
196195 )
197196}
197+ function getWidthWithPadding ( element : HTMLElement ) {
198+ const computedStyle = getComputedStyle ( element )
199+ return parseFloat ( computedStyle . width )
200+ }
198201function getHeightWithoutPadding (
199202 element : HTMLElement | null
200203) {
Original file line number Diff line number Diff line change @@ -65,8 +65,6 @@ const x = (y) => y++ * foobarbaz
6565 )
6666 } , [ ] )
6767
68- console . log ( { tween } )
69-
7068 return (
7169 < WithProgress >
7270 { progress => (
You can’t perform that action at this time.
0 commit comments