mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
Restore focus also when switching syntax highlighting on
The same already happens when switching it off, see line #249. I noticed there is still a (random?) chance the selection gets lost when switching back and forth between syntax highlighting on and off. This is not what this patch is about. Bug: T298488 Change-Id: I541f96be9e6fb2f9032df4b86657d01f0eac5679
This commit is contained in:
parent
92051b550f
commit
963e636f83
|
@ -112,7 +112,8 @@
|
||||||
var $codeMirror, cmOptions,
|
var $codeMirror, cmOptions,
|
||||||
selectionStart = $textbox1.prop( 'selectionStart' ),
|
selectionStart = $textbox1.prop( 'selectionStart' ),
|
||||||
selectionEnd = $textbox1.prop( 'selectionEnd' ),
|
selectionEnd = $textbox1.prop( 'selectionEnd' ),
|
||||||
scrollTop = $textbox1.scrollTop();
|
scrollTop = $textbox1.scrollTop(),
|
||||||
|
hasFocus = $textbox1.is( ':focus' );
|
||||||
|
|
||||||
// If CodeMirror is already loaded or wikEd gadget is enabled, abort. See T178348.
|
// If CodeMirror is already loaded or wikEd gadget is enabled, abort. See T178348.
|
||||||
// FIXME: Would be good to replace the wikEd check with something more generic.
|
// FIXME: Would be good to replace the wikEd check with something more generic.
|
||||||
|
@ -168,6 +169,9 @@
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
if ( hasFocus ) {
|
||||||
|
codeMirror.focus();
|
||||||
|
}
|
||||||
codeMirror.doc.setSelection( codeMirror.doc.posFromIndex( selectionEnd ), codeMirror.doc.posFromIndex( selectionStart ) );
|
codeMirror.doc.setSelection( codeMirror.doc.posFromIndex( selectionEnd ), codeMirror.doc.posFromIndex( selectionStart ) );
|
||||||
codeMirror.scrollTo( null, scrollTop );
|
codeMirror.scrollTo( null, scrollTop );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue