From f9ecb5b2dee9ef4da84da3156f337324e4e29e90 Mon Sep 17 00:00:00 2001 From: MusikAnimal Date: Wed, 10 Apr 2024 11:54:37 -0400 Subject: [PATCH] Use dispatchEvent instead of jQuery triggerHandler for focus/blur events triggerHandler will not bubble up the DOM, which is necessary for some listeners such as Charinsert. This patch applies the fix to both CodeMirror 5 and CodeMirror 6. Bug: T361465 Change-Id: I4c01b031de0b19d72b6f2c31566a7f9cc0b02ad8 --- resources/codemirror.js | 8 ++++++-- resources/legacy/ext.CodeMirror.WikiEditor.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/codemirror.js b/resources/codemirror.js index 04f6336a..5133931e 100644 --- a/resources/codemirror.js +++ b/resources/codemirror.js @@ -104,8 +104,12 @@ class CodeMirror { this.dirExtension, EditorState.readOnly.of( this.readOnly ), EditorView.domEventHandlers( { - blur: () => this.$textarea.triggerHandler( 'blur' ), - focus: () => this.$textarea.triggerHandler( 'focus' ) + blur: () => { + this.$textarea[ 0 ].dispatchEvent( new Event( 'blur' ) ); + }, + focus: () => { + this.$textarea[ 0 ].dispatchEvent( new Event( 'focus' ) ); + } } ), EditorView.lineWrapping, keymap.of( [ diff --git a/resources/legacy/ext.CodeMirror.WikiEditor.js b/resources/legacy/ext.CodeMirror.WikiEditor.js index ec28c4b1..6c6ee094 100644 --- a/resources/legacy/ext.CodeMirror.WikiEditor.js +++ b/resources/legacy/ext.CodeMirror.WikiEditor.js @@ -191,10 +191,10 @@ function init() { const $codeMirror = $( codeMirror.getWrapperElement() ); codeMirror.on( 'focus', () => { - $textbox1.triggerHandler( 'focus' ); + $textbox1[ 0 ].dispatchEvent( new Event( 'focus' ) ); } ); codeMirror.on( 'blur', () => { - $textbox1.triggerHandler( 'blur' ); + $textbox1[ 0 ].dispatchEvent( new Event( 'blur' ) ); } ); mw.hook( 'editRecovery.loadEnd' ).add( ( data ) => { codeMirror.on( 'change', data.fieldChangeHandler );