Skip to content
This repository was 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
petetnt merged 13 commits into
adobe:masterfrom
bmax:fix_issue_8142
Aug 26, 2016
Merged

petetnt merged 13 commits into
adobe:masterfrom
bmax:fix_issue_8142

Conversation

@bmax

@bmax bmax commented Feb 28, 2016

Copy link
Copy Markdown
Contributor

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.

Comment thread src/editor/CodeHintList.js Outdated
* @param {KeyBoardEvent} keyEvent
*/
CodeHintList.prototype.isHandlingKeyCode = function (keyCode) {
CodeHintList.prototype.isHandlingEvent = function (event) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

abose commented Feb 28, 2016

Copy link
Copy Markdown
Contributor

@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

bmax commented Feb 28, 2016

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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

petetnt commented Feb 28, 2016

Copy link
Copy Markdown
Collaborator

Made some initial comments. 👍

Comment thread src/editor/CodeHintManager.js Outdated
// if the response is true, end the session and begin another
if (response === true) {
var previousEditor = sessionEditor;
//_endSession();

Copy link
Copy Markdown
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

sprintr commented Feb 29, 2016

Copy link
Copy Markdown
Contributor

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

bmax commented Feb 29, 2016

Copy link
Copy Markdown
Contributor Author

@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

bmax commented Feb 29, 2016

Copy link
Copy Markdown
Contributor Author

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?

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
Copy Markdown
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

abose commented Mar 31, 2016

Copy link
Copy Markdown
Contributor

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

@petetnt

petetnt commented Apr 4, 2016

Copy link
Copy Markdown
Collaborator

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

@petetnt

petetnt commented Jun 24, 2016 •

Copy link
Copy Markdown
Collaborator

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

bmax commented Jun 29, 2016

Copy link
Copy Markdown
Contributor Author

@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

petetnt commented Jun 29, 2016

Copy link
Copy Markdown
Collaborator

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

abose commented Jul 2, 2016

Copy link
Copy Markdown
Contributor

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

@bmax
bmax force-pushed the fix_issue_8142 branch from 4e3e2d4 to e9336d7 Compare July 2, 2016 15:26
@bmax
bmax force-pushed the fix_issue_8142 branch from e9336d7 to 50619f2 Compare July 2, 2016 18:27
@bmax

bmax commented Jul 2, 2016

Copy link
Copy Markdown
Contributor Author

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

@petetnt

petetnt commented Jul 2, 2016

Copy link
Copy Markdown
Collaborator

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

zaggino commented Aug 25, 2016

Copy link
Copy Markdown
Contributor

@petetnt this is proably waiting for you

@petetnt

petetnt commented Aug 26, 2016

Copy link
Copy Markdown
Collaborator

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
Copy Markdown

@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.

7 participants