File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ export function CodeEditor({
7979} : CodeInputProps ) {
8080 const refHighlighting = useRef < HTMLPreElement | null > ( null )
8181 const refTextarea = useRef < HTMLTextAreaElement | null > ( null )
82+ const refLineNumbers = useRef < HTMLSpanElement | null > ( null )
8283
8384 const [ heightPx , setHeightPx ] = useState < number > ( 0 )
8485 const hljs = useHLJS ( )
@@ -89,6 +90,9 @@ export function CodeEditor({
8990 function syncScroll ( ) {
9091 refHighlighting . current ! . scrollLeft = refTextarea . current ! . scrollLeft
9192 refHighlighting . current ! . scrollTop = refTextarea . current ! . scrollTop
93+ if ( refLineNumbers . current ) {
94+ refLineNumbers . current . scrollTop = refTextarea . current ! . scrollTop
95+ }
9296 }
9397
9498 function handleInput ( _ : React . FormEvent < HTMLTextAreaElement > ) {
@@ -186,10 +190,12 @@ export function CodeEditor({
186190 dangerouslySetInnerHTML = { { __html : highlightHTML ( hljs , lang , handleNewLines ( content ) ) } }
187191 > </ pre >
188192 < span
193+ ref = { refLineNumbers }
189194 className = {
190195 "line-number-rows font-mono absolute pointer-events-none text-default-500 top-0 left-1 " +
191196 `border-solid border-default-300 border-r-1 ${ tst } `
192197 }
198+ style = { { height : `${ heightPx } px` , overflow : "hidden" } }
193199 >
194200 { Array . from ( { length : lineCount } , ( _ , idx ) => {
195201 return < span key = { idx } />
You can’t perform that action at this time.
0 commit comments