From 036b7c28a377e45e34d0fe56a797ac564b316e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 8 Jun 2020 19:47:08 +0200 Subject: [PATCH] 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 --- modules/jquery.wikiEditor.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/jquery.wikiEditor.js b/modules/jquery.wikiEditor.js index be8f1d46..78fa6c99 100644 --- a/modules/jquery.wikiEditor.js +++ b/modules/jquery.wikiEditor.js @@ -448,10 +448,7 @@ saveSelection: function () { context.$focusedElem = $( ':focus' ); context.$textarea.trigger( 'focus' ); - context.savedSelection = { - selectionStart: context.$textarea[ 0 ].selectionStart, - selectionEnd: context.$textarea[ 0 ].selectionEnd - }; + context.savedSelection = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } ); }, /** @@ -460,7 +457,7 @@ restoreSelection: function () { if ( context.savedSelection ) { 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; } if ( context.$focusedElem ) {