@@ -29,42 +29,39 @@ func codeBoxComponent(props Props) *Element {
2929 lineNumsRef = UseRef ()
3030 )
3131
32- newCBA := func () * codeBoxAssistant {
33- return & codeBoxAssistant {
34- curCode : curCode ,
35- setCode : setCode ,
36- onSave : onSave ,
37- onEscape : onEscape ,
38- textAreaRef : textAreaRef ,
39- }
40- }
41-
4232 onInput := UseCallback (func (e * js.Object ) {
43- code := e .Get (`target` ).Get (`value` ).String ()
33+ newCode := e .Get (`target` ).Get (`value` ).String ()
4434 sel := getSelection (textAreaRef )
45- globals .UndoRedo ().RecordCodeChange (sel , curCode , code )
46- setCode (code )
47- }, []any {curCode })
35+ globals .UndoRedo ().RecordCodeChange (sel , curCode , newCode )
36+ setCode (newCode )
37+ }, []any {curCode , setCode , textAreaRef })
4838
4939 onKeyDown := UseCallback (func (e * js.Object ) {
5040 key := e .Get (`key` ).String ()
5141 shift := e .Get (`shiftKey` ).Bool ()
5242 ctrl := e .Get (`metaKey` ).Bool () || e .Get (`ctrlKey` ).Bool ()
53- if editor .ProcessKeyDown (newCBA (), key , shift , ctrl ) {
43+ cba := & codeBoxAssistant {
44+ curCode : curCode ,
45+ setCode : setCode ,
46+ onSave : onSave ,
47+ onEscape : onEscape ,
48+ textAreaRef : textAreaRef ,
49+ }
50+ if editor .ProcessKeyDown (cba , key , shift , ctrl ) {
5451 e .Call (`preventDefault` )
5552 e .Call (`stopPropagation` )
5653 }
57- }, []any {curCode })
54+ }, []any {curCode , setCode , onSave , onEscape , textAreaRef })
5855
5956 onScroll := UseCallback (func (e * js.Object ) {
6057 scrollTop := e .Get (`target` ).Get (`scrollTop` ).Int ()
6158 lineNumsRef .Set (`scrollTop` , scrollTop )
62- }, []any {})
59+ }, []any {lineNumsRef })
6360
6461 onSelect := UseCallback (func (e * js.Object ) {
6562 // Don't normalize the selection so that the direction is preserved.
6663 globals .UndoRedo ().RecordSelectionChange (getSelection (textAreaRef ))
67- }, []any {})
64+ }, []any {textAreaRef })
6865
6966 // TODO(grantnelson-wf): If it is possible to detect a paste event,
7067 // then maybe we could indent the pasted code automatically to match
0 commit comments