@@ -25,12 +25,22 @@ func codeBoxComponent(props Props) *Element {
2525 textAreaRef : UseRef (),
2626 lineNumsRef : UseRef (),
2727 }
28+
2829 lineCount := strings .Count (cba .curCode , "\n " ) + 1
30+ lineNumbers := UseMemo (func () string {
31+ return getLineNumbers (lineCount )
32+ }, []any {lineCount })
2933
3034 return Div (Props {
3135 `id` : `code-box` ,
3236 },
33- codeLineBox (lineCount , cba .lineNumsRef ),
37+ TextArea (Props {
38+ `id` : `line-nums` ,
39+ `ref` : cba .lineNumsRef ,
40+ `value` : lineNumbers ,
41+ `readOnly` : true ,
42+ `disable` : `true` ,
43+ }),
3444 TextArea (Props {
3545 `id` : `code` ,
3646 `ref` : cba .textAreaRef ,
@@ -47,36 +57,6 @@ func codeBoxComponent(props Props) *Element {
4757 )
4858}
4959
50- func codeLineBox (lineCount int , ref * Ref ) * Element {
51- return CreateElement (codeLineBoxComponent , Props {
52- `lineCount` : lineCount ,
53- `ref` : ref ,
54- })
55- }
56-
57- func codeLineBoxComponent (props Props ) * Element {
58- lineCount := int (As [float64 ](props , `lineCount` ))
59- ref := props [`ref` ]
60-
61- var sb strings.Builder
62- for i := 1 ; i <= lineCount ; i ++ {
63- sb .WriteString (strconv .Itoa (i ))
64- if i < lineCount {
65- sb .WriteString ("\n " )
66- }
67- }
68-
69- print (lineCount ) // TODO(grantnelson-wf): Remove
70-
71- return TextArea (Props {
72- `id` : `line-nums` ,
73- `ref` : ref ,
74- `value` : sb .String (),
75- `readOnly` : true ,
76- `disable` : `true` ,
77- })
78- }
79-
8060type codeBoxAssistant struct {
8161 curCode string
8262 setCode func (any )
@@ -318,6 +298,17 @@ func (cba *codeBoxAssistant) findMatchingOpeningBrace(caret int) int {
318298 return - 1
319299}
320300
301+ func getLineNumbers (lineCount int ) string {
302+ var sb strings.Builder
303+ for i := 1 ; i <= lineCount ; i ++ {
304+ sb .WriteString (strconv .Itoa (i ))
305+ if i < lineCount {
306+ sb .WriteString ("\n " )
307+ }
308+ }
309+ return sb .String ()
310+ }
311+
321312func (cba * codeBoxAssistant ) getSelection () (int , int ) {
322313 start := cba .textAreaRef .Get (`selectionStart` ).Int ()
323314 end := cba .textAreaRef .Get (`selectionEnd` ).Int ()
0 commit comments