mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
CodeMirror support for WikiEditor keyboard shortcuts
Forward keydown events on the CodeMirror DOM element to the #wpTextbox1 element, on which WikiEditor's handlers are registered. CM6 support to come later. Bug: T62928 Depends-On: I18db5b6c53000457524573a9ae06939e8df0dc4f Change-Id: I0e67f2db6b29636fe25583e926a9fb12a69e3851
This commit is contained in:
parent
7add5426ea
commit
bc897f3002
|
@ -196,6 +196,16 @@ function init() {
|
||||||
codeMirror.on( 'blur', () => {
|
codeMirror.on( 'blur', () => {
|
||||||
$textbox1[ 0 ].dispatchEvent( new Event( 'blur' ) );
|
$textbox1[ 0 ].dispatchEvent( new Event( 'blur' ) );
|
||||||
} );
|
} );
|
||||||
|
codeMirror.on( 'keydown', ( _, e ) => {
|
||||||
|
if ( e.ctrlKey || e.metaKey ) {
|
||||||
|
// Possibly a WikiEditor keyboard shortcut
|
||||||
|
if ( !$textbox1[ 0 ].dispatchEvent( new KeyboardEvent( 'keydown', e ) ) ) {
|
||||||
|
// If it was actually a WikiEditor keyboard shortcut, the default would be prevented
|
||||||
|
// for the dispatched event and hence dispatchEvent() would return false
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
mw.hook( 'editRecovery.loadEnd' ).add( ( data ) => {
|
mw.hook( 'editRecovery.loadEnd' ).add( ( data ) => {
|
||||||
codeMirror.on( 'change', data.fieldChangeHandler );
|
codeMirror.on( 'change', data.fieldChangeHandler );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in a new issue