jenkins-bot has submitted this change and it was merged.

Change subject: After switching editors, move cursor to end
......................................................................


After switching editors, move cursor to end

Bug: T97290
Change-Id: I65b1ab617f1956c9269ef45fa512a37eb2ce02dc
---
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
4 files changed, 41 insertions(+), 1 deletion(-)

Approvals:
  Sbisson: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
index f3ac915..c25204a 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
@@ -125,12 +125,20 @@
        /**
         * Focus on the editor.
         *
-        * @method
         * @abstract
+        * @method
         */
        mw.flow.ui.AbstractEditorWidget.prototype.focus = null;
 
        /**
+        * Move the cursor to the end of the editor.
+        *
+        * @abstract
+        * @method
+        */
+       mw.flow.ui.AbstractEditorWidget.prototype.moveCursorToEnd = null;
+
+       /**
         * Destroy the editor widget.
         */
        mw.flow.ui.AbstractEditorWidget.prototype.destroy = function () {
diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
index 41234bc..fe25ed6 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
@@ -138,6 +138,20 @@
        /**
         * @inheritdoc
         */
+       mw.flow.ui.VisualEditorWidget.prototype.moveCursorToEnd = function () {
+               if ( !this.target ) {
+                       return;
+               }
+
+               var data = this.target.surface.getModel().getDocument().data,
+                       cursorPos = data.getNearestContentOffset( 
data.getLength(), -1 );
+
+               this.target.surface.getModel().setLinearSelection( new 
ve.Range( cursorPos ) );
+       };
+
+       /**
+        * @inheritdoc
+        */
        mw.flow.ui.VisualEditorWidget.prototype.getContent = function () {
                var doc, html;
 
diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
index 7f2af16..d75c6cf 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
@@ -120,6 +120,23 @@
        /**
         * @inheritdoc
         */
+       mw.flow.ui.WikitextEditorWidget.prototype.moveCursorToEnd = function () 
{
+               // TODO: After Ia63e6c6a0 is merged and released in OOjs UI, we 
can do:
+               // this.input.moveCursorToEnd();
+               var textRange,
+                       element = this.input.$input[0];
+               if ( element.selectionStart !== undefined ) {
+                       element.selectionStart = element.selectionEnd = 
element.value.length;
+               } else if ( element.createTextRange ) {
+                       textRange = element.createTextRange();
+                       textRange.collapse( false );
+                       textRange.select();
+               }
+       };
+
+       /**
+        * @inheritdoc
+        */
        mw.flow.ui.WikitextEditorWidget.prototype.getContent = function () {
                return this.input.getValue();
        };
diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js 
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
index 0e85a31..2c49abb 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
@@ -272,6 +272,7 @@
 
                                if ( shouldFocus ) {
                                        newEditor.focus();
+                                       newEditor.moveCursorToEnd();
                                }
                        } )
                        .fail( function ( error ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/232785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I65b1ab617f1956c9269ef45fa512a37eb2ce02dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to