Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 936dda1

Browse files
committed
Merge pull request #9624 from adobe/randy/issue-9547
Fix scroll position jumping for few cases
2 parents 5e6b9cf + 91c30cd commit 936dda1

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/search/QuickOpen.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ define(function (require, exports, module) {
363363
}
364364

365365
if (doClose) {
366-
this.close();
366+
this.close(null, null, true);
367367
MainViewManager.focusActivePane();
368368
}
369369
};
@@ -414,7 +414,7 @@ define(function (require, exports, module) {
414414
setTimeout(function () {
415415
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
416416
// Restore original selection / scroll pos
417-
self.close(self._origScrollPos, self._origSelections);
417+
self.close(self._origScrollPos, self._origSelections, true);
418418
} else if (e.keyCode === KeyEvent.DOM_VK_RETURN) {
419419
self._handleItemSelect(null, $(".smart_autocomplete_highlight").get(0)); // calls close() too
420420
}
@@ -472,9 +472,11 @@ define(function (require, exports, module) {
472472
* position when closing the ModalBar.
473473
* @param Array.<{{start:{line:number, ch:number}, end:{line:number, ch:number}, primary:boolean, reversed:boolean}}>
474474
* selections If specified, restore the given selections when closing the ModalBar.
475+
* @param {boolean=} keepScrollPos Adjust scroll pos to keep current position when modal bar closes.
476+
* Useful for Go to Line case where doc is scrolled, but don't know actual scroll pos to set so let modal bar figure it out.
475477
* @return {$.Promise} Resolved when the search bar is entirely closed.
476478
*/
477-
QuickNavigateDialog.prototype.close = function (scrollPos, selections) {
479+
QuickNavigateDialog.prototype.close = function (scrollPos, selections, keepScrollPos) {
478480
if (!this.isOpen) {
479481
return this._closeDeferred.promise();
480482
}
@@ -503,7 +505,7 @@ define(function (require, exports, module) {
503505
// So we wait until after this call chain is complete before actually closing the dialog.
504506
var self = this;
505507
setTimeout(function () {
506-
self.modalBar.close(!!scrollPos).done(function () {
508+
self.modalBar.close(!!keepScrollPos).done(function () {
507509
self._closeDeferred.resolve();
508510
});
509511

@@ -786,10 +788,12 @@ define(function (require, exports, module) {
786788
* Close the dialog when the user clicks outside of it. Smart-autocomplete listens for this and automatically closes its popup,
787789
* but we want to close the whole search "dialog." (And we can't just piggyback on the popup closing event, since there are cases
788790
* where the popup closes that we want the dialog to remain open (e.g. deleting search term via backspace).
791+
* @param {!Event} e
789792
*/
790793
QuickNavigateDialog.prototype._handleDocumentMouseDown = function (e) {
791794
if (this.modalBar.getRoot().find(e.target).length === 0 && $(".smart_autocomplete_container").find(e.target).length === 0) {
792-
this.close();
795+
// User clicked in page, so ignore original scroll pos/selection to use new scroll pos/selection.
796+
this.close(null, null, true);
793797
} else {
794798
// Allow clicks in the search field to propagate. Clicks in the menu should be
795799
// blocked to prevent focus from leaving the search field.
@@ -804,7 +808,16 @@ define(function (require, exports, module) {
804808
* Close the dialog when it loses focus.
805809
*/
806810
QuickNavigateDialog.prototype._handleBlur = function (e) {
807-
this.close();
811+
var origScrollPos, origSelections,
812+
curDoc = DocumentManager.getCurrentDocument();
813+
814+
// If doc hasn't changed, restore scroll pos/selections
815+
if (curDoc && this._origDocPath === curDoc.file.fullPath) {
816+
origScrollPos = this._origScrollPos;
817+
origSelections = this._origSelections;
818+
}
819+
820+
this.close(origScrollPos, origSelections, true);
808821
};
809822

810823
/**

0 commit comments

Comments
 (0)