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