Use jQuery.textSelection API for compat with CodeMirror extension

We were already using it for almost all interactions with the editing
area, except for this code which restores the selection after closing
a dialog.

Bug: T254612
Change-Id: I26d22d9c5d64fe8c861405e65cd4464c349aeac9
This commit is contained in:
Bartosz Dziewoński 2020-06-08 19:47:08 +02:00
parent 6703fdefae
commit 036b7c28a3

View file

@ -448,10 +448,7 @@
saveSelection: function () { saveSelection: function () {
context.$focusedElem = $( ':focus' ); context.$focusedElem = $( ':focus' );
context.$textarea.trigger( 'focus' ); context.$textarea.trigger( 'focus' );
context.savedSelection = { context.savedSelection = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
selectionStart: context.$textarea[ 0 ].selectionStart,
selectionEnd: context.$textarea[ 0 ].selectionEnd
};
}, },
/** /**
@ -460,7 +457,7 @@
restoreSelection: function () { restoreSelection: function () {
if ( context.savedSelection ) { if ( context.savedSelection ) {
context.$textarea.trigger( 'focus' ); context.$textarea.trigger( 'focus' );
context.$textarea[ 0 ].setSelectionRange( context.savedSelection.selectionStart, context.savedSelection.selectionEnd ); context.$textarea.textSelection( 'setSelection', { start: context.savedSelection[ 0 ], end: context.savedSelection[ 1 ] } );
context.savedSelection = null; context.savedSelection = null;
} }
if ( context.$focusedElem ) { if ( context.$focusedElem ) {