@@ -11,7 +11,7 @@ import (
1111 "github.com/gopherjs/gopherjs.github.io/playground/internal/react"
1212)
1313
14- func CodeBox (code string , setCode react. Setter , onSave react. Setter , onEscape react.Setter ) * react.Element {
14+ func CodeBox (code string , setCode , onSave , onEscape react.Func ) * react.Element {
1515 return react .CreateElement (codeBoxComponent , react.Props {
1616 `curCode` : code ,
1717 `setCode` : setCode ,
@@ -34,7 +34,7 @@ func codeBoxComponent(props react.Props) *react.Element {
3434 newCode := e .Get (`target` ).Get (`value` ).String ()
3535 sel := getSelection (textAreaRef )
3636 globals .UndoRedo ().RecordCodeChange (sel , curCode , newCode )
37- setCode (newCode )
37+ setCode . Invoke (newCode )
3838 }, []any {curCode , setCode , textAreaRef })
3939
4040 onKeyDown := react .UseCallback (func (e * js.Object ) {
@@ -80,29 +80,33 @@ func codeBoxComponent(props react.Props) *react.Element {
8080 }, []any {lineCount })
8181
8282 return react .Div (react.Props {
83- `id` : `code-box` ,
83+ `id` : `code-box-container ` ,
8484 },
85- react .TextArea (react.Props {
86- `id` : `line-nums` ,
87- `ref` : lineNumsRef ,
88- `value` : lineNumbers ,
89- `readOnly` : true ,
90- `disable` : `true` ,
91- }),
92- react .TextArea (react.Props {
93- `id` : `code` ,
94- `ref` : textAreaRef ,
95- `value` : curCode ,
96- `onInput` : onInput ,
97- `onKeyDown` : onKeyDown ,
98- `onScroll` : onScroll ,
99- `onSelect` : onSelect ,
100- `autoFocus` : true ,
101- `autoCorrect` : `off` ,
102- `autoComplete` : `off` ,
103- `autoCapitalize` : `off` ,
104- `spellCheck` : false ,
105- }),
85+ react .Div (react.Props {
86+ `id` : `code-box` ,
87+ },
88+ react .TextArea (react.Props {
89+ `id` : `line-nums` ,
90+ `ref` : lineNumsRef ,
91+ `value` : lineNumbers ,
92+ `readOnly` : true ,
93+ `disable` : `true` ,
94+ }),
95+ react .TextArea (react.Props {
96+ `id` : `code` ,
97+ `ref` : textAreaRef ,
98+ `value` : curCode ,
99+ `onInput` : onInput ,
100+ `onKeyDown` : onKeyDown ,
101+ `onScroll` : onScroll ,
102+ `onSelect` : onSelect ,
103+ `autoFocus` : true ,
104+ `autoCorrect` : `off` ,
105+ `autoComplete` : `off` ,
106+ `autoCapitalize` : `off` ,
107+ `spellCheck` : false ,
108+ }),
109+ ),
106110 )
107111}
108112
@@ -111,7 +115,7 @@ type codeBoxAssistant struct {
111115 setCode react.Func
112116 onSave react.Func
113117 onEscape react.Func
114- textAreaRef * react.Ref
118+ textAreaRef react.Ref
115119}
116120
117121var _ common.CodeBoxWrapper = (* codeBoxAssistant )(nil )
@@ -121,9 +125,9 @@ func (cba *codeBoxAssistant) Code() string { return cba.curCode }
121125func (cba * codeBoxAssistant ) EmitEvent (event common.Event ) {
122126 switch event {
123127 case common .SaveEvent :
124- cba .onSave ()
128+ cba .onSave . Invoke ()
125129 case common .EscapeEvent :
126- cba .onEscape ()
130+ cba .onEscape . Invoke ()
127131 case common .UndoEvent :
128132 globals .UndoRedo ().PerformUndo (cba )
129133 case common .RedoEvent :
@@ -148,7 +152,7 @@ func (cba *codeBoxAssistant) SetCode(sel common.Selection, code string) {
148152 globals .UndoRedo ().AddBreak ()
149153
150154 // Update the code state for react.
151- cba .setCode (code )
155+ cba .setCode . Invoke (code )
152156
153157 // Pre-update the textarea value so that the caret and scroll can be set
154158 // correctly before the next render so that the next render doesn't reset them.
@@ -167,7 +171,7 @@ func (cba *codeBoxAssistant) SetCode(sel common.Selection, code string) {
167171 horizontallyAutoScroll (cba .textAreaRef , sel .End , code )
168172}
169173
170- func verticallyAutoScroll (textAreaRef * react.Ref , caret int , code string ) {
174+ func verticallyAutoScroll (textAreaRef react.Ref , caret int , code string ) {
171175 textArea := textAreaRef .Current ()
172176 totalHeight := textArea .Get (`scrollHeight` ).Int ()
173177 visibleHeight := textArea .Get (`clientHeight` ).Int ()
@@ -187,7 +191,7 @@ func verticallyAutoScroll(textAreaRef *react.Ref, caret int, code string) {
187191 }
188192}
189193
190- func horizontallyAutoScroll (textAreaRef * react.Ref , caret int , code string ) {
194+ func horizontallyAutoScroll (textAreaRef react.Ref , caret int , code string ) {
191195 textArea := textAreaRef .Current ()
192196 totalWidth := textArea .Get (`scrollWidth` ).Int ()
193197 visibleWidth := textArea .Get (`clientWidth` ).Int ()
@@ -208,15 +212,15 @@ func horizontallyAutoScroll(textAreaRef *react.Ref, caret int, code string) {
208212 }
209213}
210214
211- func getSelection (textAreaRef * react.Ref ) common.Selection {
215+ func getSelection (textAreaRef react.Ref ) common.Selection {
212216 textArea := textAreaRef .Current ()
213217 start := textArea .Get (`selectionStart` ).Int ()
214218 end := textArea .Get (`selectionEnd` ).Int ()
215219 return common.Selection {Start : start , End : end }
216220}
217221
218222// setSelection sets the selection on the given textarea ref.
219- func setSelection (textAreaRef * react.Ref , sel common.Selection ) {
223+ func setSelection (textAreaRef react.Ref , sel common.Selection ) {
220224 textArea := textAreaRef .Current ()
221225 textArea .Set (`selectionStart` , sel .Start )
222226 textArea .Set (`selectionEnd` , sel .End )
0 commit comments