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

Fix for issue #8142: "Ctrl + Space" should move to the next entry when the code hint menu is open #12251

Merged
merged 13 commits into from
Aug 26, 2016

Conversation

bmax
Copy link
Contributor

@bmax bmax commented Feb 28, 2016

Hello,

Here is my suggested fix for #8142. There are a couple of lines of code that I changed and on each line I will comment and explain. I am new to Open Source and am sure this is not the best way! Any feedback is welcomed.

*/
CodeHintList.prototype.isHandlingKeyCode = function (keyCode) {
CodeHintList.prototype.isHandlingEvent = function (event) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to isHandlingEvent so that we could check the actual event object to make sure ctrlKey is called.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially a breaking change. One way would be deprecating the isHandlingKeyCode method, throwing a deprecation warning, constructing a new event with the keycode and passing it to the isHandlingEvent-method.

Another (simpler) way would be keeping the isHandlingKeyCode and checking the type, such as

CodeHintList.prototype.isHandlingKeyCode = function (keyCodeOrEvent) {
  var keyCode = typeof keyCodeOrEvent === "object" ? keyCodeOrEvent.keyCode || keyCodeOrEvent;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, type checking the argument seems to be better. else the public API will break.
Also, keep the existing function name and functionality intact.

@abose
Copy link
Contributor

abose commented Feb 28, 2016

@bmax Thank you for contributing to Brackets. You will need to Accept the Brackets CLA before we can merge this pull request.
For discussions with the brackets community or any assistance/queries, please join the brackets slack channel by sending a mail to admin@brackets.io with the subject line slack registration request specifying the email addresses you would like to register.
Also, join brackets dev google groups link here..

@bmax
Copy link
Contributor Author

bmax commented Feb 28, 2016

@abose Thank you for the quick response. I emailed for slack registration and also accepted CLA.

*/
CodeHintList.prototype.isHandlingKeyCode = function (keyCode) {
CodeHintList.prototype.isHandlingEvent = function (event) {
var keyCode = event.keyCode;
return (keyCode === KeyEvent.DOM_VK_UP || keyCode === KeyEvent.DOM_VK_DOWN ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this check is getting pretty behemothy and could be refactored somehow.

@petetnt
Copy link
Collaborator

petetnt commented Feb 28, 2016

Made some initial comments. 👍

// if the response is true, end the session and begin another
if (response === true) {
var previousEditor = sessionEditor;
//_endSession();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code.

@sprintr
Copy link
Contributor

sprintr commented Feb 29, 2016

A couple of issues I am facing with this PR.

$(".foo").
  1. Making an explicit request here makes the code hints flash in and flash out. You don't get a chance to select any of the hints.
  2. It should show the first hint when explicitly requested and should move top-to-bottom rather than bottom-to-top.

@bmax
Copy link
Contributor Author

bmax commented Feb 29, 2016

@sprintr Thank you! 1. I did not think about the case of implicit calls and not sure why it flashes in and out only sometimes but other times it stays open fine. 2. easy fix, will be in next commit.

@bmax
Copy link
Contributor Author

bmax commented Feb 29, 2016

Found a small problem with my fix, If you have hint list keyboard shortcut set to ctrl+space then when you open the list, it automatically jumps to the end of the list. One way I can think of fixing this is making codeHintOpened a boolean and when it is >= 1 then allow the ctrl+space command to work. Any better ideas or suggestions?

return (keyCode === KeyEvent.DOM_VK_UP || keyCode === KeyEvent.DOM_VK_DOWN ||
keyCode === KeyEvent.DOM_VK_PAGE_UP || keyCode === KeyEvent.DOM_VK_PAGE_DOWN ||
keyCode === KeyEvent.DOM_VK_RETURN ||
keyCode === KeyEvent.DOM_VK_CONTROL ||
(ctrlKey && keyCode === KeyEvent.DOM_VK_SPACE) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: linting error here (should be indented to column 20, not 17)

@abose
Copy link
Contributor

abose commented Mar 31, 2016

Pinging @bmax
Hope you got time to look into the issues raised by @petetnt

@petetnt
Copy link
Collaborator

petetnt commented Apr 4, 2016

We made some progress with @bmax last weekend but there's still some (small) issues withstanding regarding two failing tests. 🚒

@petetnt
Copy link
Collaborator

petetnt commented Jun 24, 2016

I fixed the errors in the tests, see the attached diff

diff --git a/src/editor/CodeHintList.js b/src/editor/CodeHintList.js
index 24b8e92..e0edc2c 100644
--- a/src/editor/CodeHintList.js
+++ b/src/editor/CodeHintList.js
@@ -320,6 +320,7 @@ define(function (require, exports, module) {
                 keyCode === KeyEvent.DOM_VK_PAGE_UP || keyCode === KeyEvent.DOM_VK_PAGE_DOWN ||
                 keyCode === KeyEvent.DOM_VK_RETURN ||
                 keyCode === KeyEvent.DOM_VK_CONTROL ||
+                keyCode === KeyEvent.DOM_VK_ESCAPE ||
                 (ctrlKey && keyCode === KeyEvent.DOM_VK_SPACE) ||
                 (keyCode === KeyEvent.DOM_VK_TAB && this.insertHintOnTab));
     };
@@ -394,11 +395,12 @@ define(function (require, exports, module) {
         if (event.type === "keydown" && this.isHandlingKeyCode(event)) {
             keyCode = event.keyCode;

-            if (event.shiftKey &&
-                    (event.keyCode === KeyEvent.DOM_VK_UP ||
-                     event.keyCode === KeyEvent.DOM_VK_DOWN ||
-                     event.keyCode === KeyEvent.DOM_VK_PAGE_UP ||
-                     event.keyCode === KeyEvent.DOM_VK_PAGE_DOWN)) {
+            if (event.keyCode === KeyEvent.DOM_VK_ESCAPE ||
+                    (event.shiftKey &&
+                        (event.keyCode === KeyEvent.DOM_VK_UP ||
+                        event.keyCode === KeyEvent.DOM_VK_DOWN ||
+                        event.keyCode === KeyEvent.DOM_VK_PAGE_UP ||
+                        event.keyCode === KeyEvent.DOM_VK_PAGE_DOWN))) {
                 this.handleClose();

                 // Let the event bubble.
@@ -406,7 +408,7 @@ define(function (require, exports, module) {
             } else if (keyCode === KeyEvent.DOM_VK_UP) {
                 _rotateSelection.call(this, -1);
             } else if (keyCode === KeyEvent.DOM_VK_DOWN ||
-                (event.ctrlKey && keyCode === KeyEvent.DOM_VK_SPACE)) {
+                    (event.ctrlKey && keyCode === KeyEvent.DOM_VK_SPACE)) {
                 _rotateSelection.call(this, 1);
             } else if (keyCode === KeyEvent.DOM_VK_PAGE_UP) {
                 _rotateSelection.call(this, -_itemsPerPage());
diff --git a/src/editor/CodeHintManager.js b/src/editor/CodeHintManager.js
index e31e4b6..c3a776b 100644
--- a/src/editor/CodeHintManager.js
+++ b/src/editor/CodeHintManager.js
@@ -563,7 +563,8 @@ define(function (require, exports, module) {
     function _handleKeyupEvent(jqEvent, editor, event) {
         keyDownEditor = editor;
         if (_inSession(editor)) {
-            if (event.keyCode === KeyEvent.DOM_VK_HOME || event.keyCode === KeyEvent.DOM_VK_END) {
+            if (event.keyCode === KeyEvent.DOM_VK_HOME ||
+                    event.keyCode === KeyEvent.DOM_VK_END) {
                 _endSession();
             } else if (event.keyCode === KeyEvent.DOM_VK_LEFT ||
                        event.keyCode === KeyEvent.DOM_VK_RIGHT ||
@@ -712,6 +713,16 @@ define(function (require, exports, module) {

     EditorManager.on("activeEditorChange", activeEditorChangeHandler);

+    // Dismiss code hints before executing any command other than showing code hints since the command
+    // may make the current hinting session irrevalent after execution.
+    // For example, when the user hits Ctrl+K to open Quick Doc, it is
+    // pointless to keep the hint list since the user wants to view the Quick Doc.
+    CommandManager.on("beforeExecuteCommand", function (event, commandId) {
+        if (commandId !== Commands.SHOW_CODE_HINTS) {
+            _endSession();
+        }
+    });
+    
     CommandManager.register(Strings.CMD_SHOW_CODE_HINTS, Commands.SHOW_CODE_HINTS, _startNewSession);

     exports._getCodeHintList        = _getCodeHintList;

First do git fetch origin master && git rebase origin/master, then apply that patch and run the tests -> all tests pass.

@bmax
Copy link
Contributor Author

bmax commented Jun 29, 2016

@petetnt @abose This pull request should be ready to commit. I added two new tests to support the fix. I apologize about the terrible commit history, not sure if I should clean it up.

@petetnt
Copy link
Collaborator

petetnt commented Jun 29, 2016

Great job @bmax, LGTM.

For the commit history, I think the one who merges this PR should just do a squash & merge in the GitHub UI.

@abose
Copy link
Contributor

abose commented Jul 2, 2016

👍 @bmax . can you squash some of the commits?
Tagging @swmitra code hints related change.

@bmax
Copy link
Contributor Author

bmax commented Jul 2, 2016

@abose Done! Let me know if that looks better.

@petetnt
Copy link
Collaborator

petetnt commented Jul 2, 2016

Again LGTM. It's pretty hard to squash this further manually, if needed I suggest just merging this with squash & merge on GitHub UI.

@ficristo ficristo changed the title Fix for issue #8142 Fix for issue #8142: "Ctrl + Space" should move to the next entry when the code hint menu is open Aug 14, 2016
@zaggino
Copy link
Contributor

zaggino commented Aug 25, 2016

@petetnt this is proably waiting for you

@petetnt
Copy link
Collaborator

petetnt commented Aug 26, 2016

Merging this. Thanks for this get PR and for your extended patience @bmax 👍

@petetnt petetnt merged commit 63962ce into adobe:master Aug 26, 2016
@ficristo ficristo added this to the Release 1.8 milestone Aug 26, 2016
@adityapaturi
Copy link

@petetnt and @bmax : This change has introduced a new issue #12799. Please have a look

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants