mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 22:03:28 +00:00
Preserve scroll position when switching
This will be slightly off when you have scrolled past headers which have a different font size, but it's better than jumping back to the top of the document. Change-Id: I62a73c30932c3dc1e538484edead9c5d2ed6c72f
This commit is contained in:
parent
95247b0aab
commit
643faba0db
|
@ -327,17 +327,23 @@
|
|||
* Enables or disables CodeMirror
|
||||
*/
|
||||
function switchCodeMirror() {
|
||||
var scrollTop,
|
||||
$textbox1 = $( '#wpTextbox1' );
|
||||
|
||||
if ( codeMirror ) {
|
||||
scrollTop = codeMirror.getScrollInfo().top;
|
||||
setCodeEditorPreference( false );
|
||||
codeMirror.save();
|
||||
codeMirror.toTextArea();
|
||||
codeMirror = null;
|
||||
$.fn.textSelection = origTextSelection;
|
||||
|
||||
$textbox1.scrollTop( scrollTop );
|
||||
} else {
|
||||
scrollTop = $textbox1.scrollTop();
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
enableCodeMirror();
|
||||
setCodeEditorPreference( true );
|
||||
codeMirror.scrollTo( 0, scrollTop );
|
||||
}
|
||||
updateToolbarButton();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue