@@ -55,7 +55,7 @@ func codeBoxComponent(props Props) *Element {
5555
5656 onScroll := UseCallback (func (e * js.Object ) {
5757 scrollTop := e .Get (`target` ).Get (`scrollTop` ).Int ()
58- lineNumsRef .Set (`scrollTop` , scrollTop )
58+ lineNumsRef .Current (). Set (`scrollTop` , scrollTop )
5959 }, []any {lineNumsRef })
6060
6161 onSelect := UseCallback (func (e * js.Object ) {
@@ -69,7 +69,7 @@ func codeBoxComponent(props Props) *Element {
6969
7070 UseEffect (func () {
7171 // On first render, focus the code textarea.
72- textAreaRef .Call (`focus` )
72+ textAreaRef .Current (). Call (`focus` )
7373 setSelection (textAreaRef , common.Selection {})
7474 }, []any {})
7575
@@ -151,7 +151,7 @@ func (cba *codeBoxAssistant) SetCode(sel common.Selection, code string) {
151151
152152 // Pre-update the textarea value so that the caret and scroll can be set
153153 // correctly before the next render so that the next render doesn't reset them.
154- cba .textAreaRef .Set (`value` , code )
154+ cba .textAreaRef .Current (). Set (`value` , code )
155155
156156 // Match the diretionallity of the prior selection.
157157 if getSelection (cba .textAreaRef ).Reversed () {
@@ -167,8 +167,9 @@ func (cba *codeBoxAssistant) SetCode(sel common.Selection, code string) {
167167}
168168
169169func verticallyAutoScroll (textAreaRef * Ref , caret int , code string ) {
170- totalHeight := textAreaRef .Get (`scrollHeight` ).Int ()
171- visibleHeight := textAreaRef .Get (`clientHeight` ).Int ()
170+ textArea := textAreaRef .Current ()
171+ totalHeight := textArea .Get (`scrollHeight` ).Int ()
172+ visibleHeight := textArea .Get (`clientHeight` ).Int ()
172173 if totalHeight <= visibleHeight {
173174 return // No vertical scrolling needed.
174175 }
@@ -177,17 +178,18 @@ func verticallyAutoScroll(textAreaRef *Ref, caret int, code string) {
177178 curLine := strings .Count (code [:caret ], "\n " ) + 1
178179 scrollTop := int (float64 (curLine ) * float64 (totalHeight ) / float64 (lineCount ))
179180
180- curTop := textAreaRef .Get (`scrollTop` ).Int ()
181+ curTop := textArea .Get (`scrollTop` ).Int ()
181182 if scrollTop < curTop {
182- textAreaRef .Set (`scrollTop` , scrollTop )
183+ textArea .Set (`scrollTop` , scrollTop )
183184 } else if scrollTop -= visibleHeight ; scrollTop > curTop {
184- textAreaRef .Set (`scrollTop` , scrollTop )
185+ textArea .Set (`scrollTop` , scrollTop )
185186 }
186187}
187188
188189func horizontallyAutoScroll (textAreaRef * Ref , caret int , code string ) {
189- totalWidth := textAreaRef .Get (`scrollWidth` ).Int ()
190- visibleWidth := textAreaRef .Get (`clientWidth` ).Int ()
190+ textArea := textAreaRef .Current ()
191+ totalWidth := textArea .Get (`scrollWidth` ).Int ()
192+ visibleWidth := textArea .Get (`clientWidth` ).Int ()
191193 if totalWidth <= visibleWidth {
192194 return // No horizontal scrolling needed.
193195 }
@@ -197,24 +199,26 @@ func horizontallyAutoScroll(textAreaRef *Ref, caret int, code string) {
197199 curLine := editor .MeasureLineLength (code [par :caret ])
198200 scrollLeft := int (float64 (curLine ) * float64 (totalWidth ) / float64 (longestLine ))
199201
200- curLeft := textAreaRef .Get (`scrollLeft` ).Int ()
202+ curLeft := textArea .Get (`scrollLeft` ).Int ()
201203 if scrollLeft < curLeft {
202- textAreaRef .Set (`scrollLeft` , scrollLeft )
204+ textArea .Set (`scrollLeft` , scrollLeft )
203205 } else if scrollLeft -= visibleWidth ; scrollLeft > curLeft {
204- textAreaRef .Set (`scrollLeft` , scrollLeft )
206+ textArea .Set (`scrollLeft` , scrollLeft )
205207 }
206208}
207209
208210func getSelection (textAreaRef * Ref ) common.Selection {
209- start := textAreaRef .Get (`selectionStart` ).Int ()
210- end := textAreaRef .Get (`selectionEnd` ).Int ()
211+ textArea := textAreaRef .Current ()
212+ start := textArea .Get (`selectionStart` ).Int ()
213+ end := textArea .Get (`selectionEnd` ).Int ()
211214 return common.Selection {Start : start , End : end }
212215}
213216
214217// setSelection sets the selection on the given textarea ref.
215218func setSelection (textAreaRef * Ref , sel common.Selection ) {
216- textAreaRef .Set (`selectionStart` , sel .Start )
217- textAreaRef .Set (`selectionEnd` , sel .End )
219+ textArea := textAreaRef .Current ()
220+ textArea .Set (`selectionStart` , sel .Start )
221+ textArea .Set (`selectionEnd` , sel .End )
218222}
219223
220224func getLineNumbers (lineCount int ) string {
0 commit comments