-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix for issue #8142: "Ctrl + Space" should move to the next entry when the code hint menu is open #12251
Conversation
*/ | ||
CodeHintList.prototype.isHandlingKeyCode = function (keyCode) { | ||
CodeHintList.prototype.isHandlingEvent = function (event) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
@bmax Thank you for contributing to Brackets. You will need to Accept the Brackets CLA before we can merge this pull request. |
@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 || |
There was a problem hiding this comment.
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.
Made some initial comments. 👍 |
// if the response is true, end the session and begin another | ||
if (response === true) { | ||
var previousEditor = sessionEditor; | ||
//_endSession(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code.
A couple of issues I am facing with this PR. $(".foo").
|
@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. |
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) || |
There was a problem hiding this comment.
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)
We made some progress with @bmax last weekend but there's still some (small) issues withstanding regarding two failing tests. 🚒 |
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 |
…with the javascript '.' character hints
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 Done! Let me know if that looks better. |
Again LGTM. It's pretty hard to squash this further manually, if needed I suggest just merging this with squash & merge on GitHub UI. |
@petetnt this is proably waiting for you |
Merging this. Thanks for this get PR and for your extended patience @bmax 👍 |
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.