mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-28 02:00:34 +00:00
Preserve textarea state when building WikiEditor UI
When we are wrapping the textarea in the Editor UI, the focus state, cursor position and the scrollposition might get lost. This is especially annoying on slower machines, where users might have started using the textarea before the WikiEditor UI was constructed. Bug: 41911 Change-Id: Ie472c6c88d98f7ba89873a2db73463ef01bd995a
This commit is contained in:
parent
4ccd57d34c
commit
effd98be7e
|
@ -486,6 +486,9 @@ if ( !context || typeof context === 'undefined' ) {
|
|||
.append( $( '<span>' + mediaWiki.msg( 'wikieditor-loading' ) + '</span>' )
|
||||
.css( 'marginTop', context.$textarea.height() / 2 ) );
|
||||
*/
|
||||
/* Preserving cursor and focus state, which will get lost due to wrapAll */
|
||||
var hasFocus = context.$textarea.is( ':focus' ),
|
||||
cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||
// Encapsulate the textarea with some containers for layout
|
||||
context.$textarea
|
||||
/* Disabling our loading div for now
|
||||
|
@ -497,6 +500,14 @@ if ( !context || typeof context === 'undefined' ) {
|
|||
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-left' ) )
|
||||
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-bottom' ) )
|
||||
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-text' ) );
|
||||
// Restore scroll position after this wrapAll (tracked by mediawiki.action.edit)
|
||||
context.$textarea.prop( 'scrollTop', $( '#wpScrolltop' ).val() );
|
||||
// Restore focus and cursor if needed
|
||||
if ( hasFocus ) {
|
||||
context.$textarea.focus();
|
||||
context.$textarea.textSelection( 'setSelection', { start: cursorPos[0], end: cursorPos[1] } );
|
||||
}
|
||||
|
||||
// Get references to some of the newly created containers
|
||||
context.$ui = context.$textarea.parent().parent().parent().parent().parent();
|
||||
context.$wikitext = context.$textarea.parent().parent().parent().parent();
|
||||
|
|
Loading…
Reference in a new issue