Interface for the classic edit toolbar (mw.toolbar) does not correctly identify the focused element when CodeMirror is enabled in Chrome and IE (in FF it works correctly).
As a result the function mw.toolbar insertTags does not work correctly.
The function can insert tags, but cannot encapsulate selection.
Problem description:
$currentFocused is wrong in Chrome and IE when CodeMirror enabled
insertTags: function ( tagOpen, tagClose, sampleText ) { if ( $currentFocused && $currentFocused.length ) { $currentFocused.textSelection( 'encapsulateSelection', { pre: tagOpen, peri: sampleText, post: tagClose } ); }
Code that set the $currentFocused variable:
$( document ).on( 'focus', 'textarea, input:text', function () { $currentFocused = $( this ); } );
This works different in IE, Chrome and FF when CodeMirror is enabled.
And corresponded code in CodeMirror:
function cmTextSelection( command, options ) { if ( !codeMirror || codeMirror.getTextArea() !== this[ 0 ] ) { return origTextSelection.call( this, command, options ); } ...
Only in FF when CodeMirror enabled and function mw.toolbar.insertTags called this[ 0 ] === codeMirror.getTextArea()
This bug was found when the CodeMirror and Charinsert extensions was used together.
Seems, it can be fixed in CodeMirror by:
function cmTextSelection( command, options ) { if ( !codeMirror /*|| codeMirror.getTextArea() !== this[ 0 ]*/ ) { return origTextSelection.call( this, command, options ); } ...
but I sure it should be fixed in MW core.
From the merged-in task:
Different results in Firefox 55 and Chromium 60 (linux)
To reproduce:
- Edit https://www.mediawiki.org/w/index.php?title=User:Quiddity_(WMF)/sandbox2&oldid=2544402 in classic wikitext mode (or same at metawiki)
- Select all (either manually or ctrl-A)
- Click one of the <opening></closing> links/buttons in MediaWiki:Edittools under the save button, e.g. <translate></translate> or <code></code>
- Result:
- Firefox: the entire block is replaced by, e.g. <translate>-</translate> (dash in middle)
- Chromium: nothing changes
Note: Removing any text from that example will result in it starting to work properly. It is currently 1001 bytes (possibly relevant?).