@@ -21,6 +21,44 @@ export const EditorPanel = ({ editorWidth }: { editorWidth: number }) => {
2121 const startHeight = useRef ( 0 ) ;
2222 const containerRef = useRef < HTMLDivElement > ( null ) ;
2323
24+ // Local state for immediate editor updates (no lag while typing)
25+ const [ localValue , setLocalValue ] = useState ( config ) ;
26+
27+ // Ref for debounce timer
28+ const debounceTimer = useRef < NodeJS . Timeout | null > ( null ) ;
29+
30+ // Sync local value when config changes from external source
31+ useEffect ( ( ) => {
32+ setLocalValue ( config ) ;
33+ } , [ config ] ) ;
34+
35+ // Cleanup debounce timer on unmount
36+ useEffect ( ( ) => {
37+ return ( ) => {
38+ if ( debounceTimer . current ) {
39+ clearTimeout ( debounceTimer . current ) ;
40+ }
41+ } ;
42+ } , [ ] ) ;
43+
44+ // Handler for editor changes - updates local state immediately and debounces actual config update
45+ const handleEditorChange = useCallback (
46+ ( _editor : any , _data : any , value : string ) => {
47+ setLocalValue ( value ) ; // Update immediately for responsive typing
48+
49+ // Clear previous timer
50+ if ( debounceTimer . current ) {
51+ clearTimeout ( debounceTimer . current ) ;
52+ }
53+
54+ // Set new timer to update config after 300ms of no typing
55+ debounceTimer . current = setTimeout ( ( ) => {
56+ setConfig ( value ) ;
57+ } , 300 ) ;
58+ } ,
59+ [ setConfig ]
60+ ) ;
61+
2462 // Drag logic for vertical resize
2563 const handleMouseDown = useCallback (
2664 ( e : MouseEvent ) => {
@@ -81,8 +119,8 @@ export const EditorPanel = ({ editorWidth }: { editorWidth: number }) => {
81119 < div className = "flex-1 min-h-0" >
82120 < CodeEditor
83121 ref = { editorRef }
84- value = { config }
85- onBeforeChange = { ( _editor : any , _data : any , value : string ) => setConfig ( value ) }
122+ value = { localValue }
123+ onBeforeChange = { handleEditorChange }
86124 border = { false }
87125 controlled
88126 // @ts -ignore
0 commit comments