From 0cee7d4575ab858ee029e95086719ac538f107ed Mon Sep 17 00:00:00 2001 From: Nitesh Kumar <38075523+niteskum@users.noreply.github.com> Date: Thu, 2 Aug 2018 18:54:10 +0530 Subject: [PATCH] Fixed ExtractToVariable Menu Close Issue due to scrolling (#14492) * Fixed ExtractToVariable Menu Close Issue due to scrolling * Addressed Review Comments * Addessed review comments * Addressed Review Comments * Addressed Review Comments --- .../JavaScriptRefactoring/ExtractToVariable.js | 13 +++++++++++++ src/widgets/InlineMenu.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js b/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js index 926d8f516a5..e5cb1b70412 100644 --- a/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js +++ b/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js @@ -303,6 +303,19 @@ define(function(require, exports, module) { inlineMenu = new InlineMenu(session.editor, Strings.EXTRACTTO_VARIABLE_SELECT_EXPRESSION); inlineMenu.onHover(function (expnId) { + // Remove the scroll Handlers If already Attached. + editor.off("scroll.inlinemenu"); + // Add a scroll handler If Selection Range is not View. + // This is Added for a Bug, where Menu used not to open for the first Time + if(!editor.isLineVisible(editor.posFromIndex(expns[expnId].end).line)) { + editor.on("scroll.inlinemenu", function() { + // Remove the Handlers so that If scroll event is triggerd again by any other operation + // Menu should not be reopened. + // Menu Should be reopened only if Scroll event is triggered by onHover. + editor.off("scroll.inlinemenu"); + inlineMenu.openRemovedMenu(); + }); + } editor.setSelection(editor.posFromIndex(expns[expnId].start), editor.posFromIndex(expns[expnId].end)); }); diff --git a/src/widgets/InlineMenu.js b/src/widgets/InlineMenu.js index 685b4bb3d13..30b34c6a2e5 100644 --- a/src/widgets/InlineMenu.js +++ b/src/widgets/InlineMenu.js @@ -413,6 +413,19 @@ define(function (require, exports, module) { } }; + /** + * Displays the last menu which was closed due to Scrolling + */ + InlineMenu.prototype.openRemovedMenu = function () { + if (this.opened === true) { + if (this.$menu && !this.$menu.hasClass("open")) { + var menuPos = this._calcMenuLocation(); + this.$menu.addClass("open") + .css({"left": menuPos.left, "top": menuPos.top, "width": menuPos.width + "px"}); + } + } + }; + /** * Closes the menu */