Skip to content

Commit 7f2a790

Browse files
committed
Merge pull request adobe#4173 from adobe/nj/issue-4172
Ignore key and close code hint session if code hint list is invisible
2 parents 37f4ffd + 8d3828c commit 7f2a790

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/editor/CodeHintList.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ define(function (require, exports, module) {
339339

340340
return itemsPerPage;
341341
}
342+
343+
// If we're no longer visible, skip handling the key and end the session.
344+
if (!this.isOpen()) {
345+
this.handleClose();
346+
return false;
347+
}
342348

343349
// (page) up, (page) down, enter and tab key are handled by the list
344350
if (event.type === "keydown" && this.isHandlingKeyCode(event.keyCode)) {
@@ -353,8 +359,7 @@ define(function (require, exports, module) {
353359

354360
// Let the event bubble.
355361
return false;
356-
}
357-
else if (keyCode === KeyEvent.DOM_VK_UP) {
362+
} else if (keyCode === KeyEvent.DOM_VK_UP) {
358363
_rotateSelection.call(this, -1);
359364
} else if (keyCode === KeyEvent.DOM_VK_DOWN) {
360365
_rotateSelection.call(this, 1);
@@ -470,8 +475,9 @@ define(function (require, exports, module) {
470475
// TODO: Due to #1381, this won't get called if the user clicks out of
471476
// the code hint menu. That's (sort of) okay right now since it doesn't
472477
// really matter if a single old invisible code hint list is lying
473-
// around (it'll get closed the next time the user pops up a code
474-
// hint). Once #1381 is fixed this issue should go away.
478+
// around (it will ignore keydown events, and it'll get closed the next
479+
// time the user pops up a code hint). Once #1381 is fixed this issue
480+
// should go away.
475481
this.handleClose = callback;
476482
};
477483

test/spec/CodeHint-test.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define(function (require, exports, module) {
3434
Commands = require("command/Commands"),
3535
EditorManager, // loaded from brackets.test
3636
CommandManager,
37-
CodeHintManager;
37+
CodeHintManager,
38+
KeyBindingManager;
3839

3940
var testPath = SpecRunnerUtils.getTestPath("/spec/CodeHint-test-files"),
4041
testWindow,
@@ -75,6 +76,7 @@ define(function (require, exports, module) {
7576
CodeHintManager = testWindow.brackets.test.CodeHintManager;
7677
EditorManager = testWindow.brackets.test.EditorManager;
7778
CommandManager = testWindow.brackets.test.CommandManager;
79+
KeyBindingManager = testWindow.brackets.test.KeyBindingManager;
7880
});
7981
});
8082

@@ -267,6 +269,48 @@ define(function (require, exports, module) {
267269
expectNoHints();
268270
});
269271
});
272+
273+
it("should stop handling keydowns if closed by a click outside", function () {
274+
var editor,
275+
pos = {line: 3, ch: 1};
276+
277+
// minimal markup with an open '<' before IP
278+
// Note: line for pos is 0-based and editor lines numbers are 1-based
279+
initCodeHintTest("test1.html", pos);
280+
281+
runs(function () {
282+
editor = EditorManager.getCurrentFullEditor();
283+
expect(editor).toBeTruthy();
284+
285+
editor.document.replaceRange("di", pos);
286+
invokeCodeHints();
287+
288+
// verify list is open
289+
expectSomeHints();
290+
291+
// get the document text and make sure it doesn't change if we
292+
// click outside and then keydown
293+
var text = editor.document.getText();
294+
295+
testWindow.$("body").click();
296+
KeyBindingManager._handleKeyEvent({
297+
keyCode: KeyEvent.DOM_VK_ENTER,
298+
stopImmediatePropagation: function () { },
299+
stopPropagation: function () { },
300+
preventDefault: function () { }
301+
});
302+
303+
// Verify that after the keydown, the session is closed
304+
// (not just the hint popup). Because of #1381, we don't
305+
// actually have a way to close the session as soon as the
306+
// popup is dismissed by Bootstrap, so we do so on the next
307+
// keydown. Eventually, once that's fixed, we should be able
308+
// to move this expectNoHints() up after the click.
309+
expectNoHints();
310+
expect(editor.document.getText()).toEqual(text);
311+
});
312+
313+
});
270314
});
271315
});
272316
});

0 commit comments

Comments
 (0)