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:
Ed Sanders 2017-07-20 19:12:38 +01:00
parent 95247b0aab
commit 643faba0db

View file

@ -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();
}