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

Change subject: FindAndReplace: Start search at current offset
......................................................................


FindAndReplace: Start search at current offset

Prevents scrolling back to the top in long documents.

Change-Id: If598685ecbe44823dcf9645d56ee5175a11e95c8
---
M src/ui/dialogs/ve.ui.FindAndReplaceDialog.js
1 file changed, 12 insertions(+), 4 deletions(-)

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



diff --git a/src/ui/dialogs/ve.ui.FindAndReplaceDialog.js 
b/src/ui/dialogs/ve.ui.FindAndReplaceDialog.js
index 0da14d0..83c49e0 100644
--- a/src/ui/dialogs/ve.ui.FindAndReplaceDialog.js
+++ b/src/ui/dialogs/ve.ui.FindAndReplaceDialog.js
@@ -52,6 +52,7 @@
        this.invalidRegex = false;
        this.$findResults = $( '<div>' ).addClass( 
've-ui-findAndReplaceDialog-findResults' );
        this.initialFragment = null;
+       this.startOffset = 0;
        this.fragments = [];
        this.results = 0;
        // Range over the list of fragments indicating which ones where 
rendered,
@@ -189,14 +190,15 @@
                        this.surface.getView().connect( this, { position: 
this.renderFragmentsDebounced } );
                        this.surface.getView().$window.on( 'scroll', 
this.onWindowScrollDebounced );
 
+                       this.initialFragment = fragment;
+                       this.startOffset = ve.getProp( 
this.initialFragment.getSelection().getRanges(), 0, 'start' ) || 0;
+
                        text = fragment.getText();
                        if ( text && text !== this.findText.getValue() ) {
                                this.findText.setValue( text );
                        } else {
                                this.onFindChange();
                        }
-
-                       this.initialFragment = fragment;
                }, this );
 };
 
@@ -244,6 +246,7 @@
                        this.$findResults.empty().detach();
                        this.fragments = [];
                        this.surface = null;
+                       this.focusedIndex = 0;
                }, this );
 };
 
@@ -298,7 +301,7 @@
  * Update search result fragments
  */
 ve.ui.FindAndReplaceDialog.prototype.updateFragments = function () {
-       var i, l,
+       var i, l, startIndex,
                surfaceModel = this.surface.getModel(),
                documentModel = surfaceModel.getDocument(),
                ranges = [],
@@ -325,10 +328,13 @@
                ranges = documentModel.findText( this.query, matchCase, true );
                for ( i = 0, l = ranges.length; i < l; i++ ) {
                        this.fragments.push( surfaceModel.getLinearFragment( 
ranges[ i ], true, true ) );
+                       if ( startIndex === undefined && ranges[ i ].start >= 
this.startOffset ) {
+                               startIndex = this.fragments.length - 1;
+                       }
                }
        }
        this.results = this.fragments.length;
-       this.focusedIndex = Math.min( this.focusedIndex, this.results ? 
this.results - 1 : 0 );
+       this.focusedIndex = startIndex || 0;
        this.nextButton.setDisabled( !this.results );
        this.previousButton.setDisabled( !this.results );
        this.replaceButton.setDisabled( !this.results );
@@ -425,6 +431,8 @@
                return;
        }
 
+       this.startOffset = this.fragments[ this.focusedIndex 
].getSelection().getRanges()[ 0 ].start;
+
        this.$findResults
                .find( '.ve-ui-findAndReplaceDialog-findResult-focused' )
                .removeClass( 've-ui-findAndReplaceDialog-findResult-focused' );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If598685ecbe44823dcf9645d56ee5175a11e95c8
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to