@@ -193,33 +193,24 @@ function initBlockTools() {
193193
194194 // blockly will prevent us from focusining on our textarea
195195 // so we need to override it via outside events
196- const textarea = editor . container . querySelector ( "textarea" ) ;
197196 const unfocusListener = ( e ) => {
198197 if ( String ( e . toElement ?. className ) . includes ( "ace" ) ) return ;
199- textarea . _lastFocusTime = undefined ;
200198
201199 editor . blur ( ) ;
202200 ScratchBlocks . mainWorkspace . allowDragging = true ;
203201 parent . setMovable ( true ) ;
204202
205203 input . removeEventListener ( "mouseleave" , unfocusListener ) ;
206204 } ;
207- editor . container . addEventListener ( "mousedown" , ( e ) => {
208- textarea . _lastFocusTime = e . timeStamp ;
209205
210- // manually unfocus when we leave the editor
206+ ScratchBlocks . bindEventWithChecks_ ( input , "mousedown" , field , ( e ) => {
207+ e . stopPropagation ( ) ;
208+ ScratchBlocks . mainWorkspace . allowDragging = false ;
209+ parent . setMovable ( false ) ;
210+ editor . focus ( ) ;
211+
211212 input . addEventListener ( "mouseleave" , unfocusListener ) ;
212213 } ) ;
213- textarea . addEventListener ( "blur" , ( e ) => {
214- if ( e . timeStamp - textarea . _lastFocusTime < 250 ) {
215- // blockly has forced unfocused this element
216- queueMicrotask ( ( ) => {
217- ScratchBlocks . mainWorkspace . allowDragging = false ;
218- parent . setMovable ( false ) ;
219- editor . focus ( ) ;
220- } ) ;
221- }
222- } ) ;
223214
224215 // allow resizing the editor
225216 const resizeHandle = document . createElement ( "div" ) ;
0 commit comments