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

Commit 32ab5ee

Browse files
committed
Merge branch 'master' of https://github.com/adobe/brackets into larz/linux-scrollbar-sqaushed
2 parents d3e359f + 2e800ef commit 32ab5ee

8 files changed

Lines changed: 622 additions & 468 deletions

File tree

src/editor/CodeHintList.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ define(function (require, exports, module) {
4343
* @constructor
4444
* @param {Editor} editor
4545
*/
46-
function CodeHintList(editor) {
46+
function CodeHintList(editor, insertHintOnTab) {
4747

4848
/**
4949
* The list of hints to display
@@ -79,6 +79,13 @@ define(function (require, exports, module) {
7979
* @type {Editor}
8080
*/
8181
this.editor = editor;
82+
83+
/**
84+
* Whether the currently selected hint should be inserted on a tab key event
85+
*
86+
* @type {boolean}
87+
*/
88+
this.insertHintOnTab = insertHintOnTab;
8289

8390
/**
8491
* The hint selection callback function
@@ -276,8 +283,8 @@ define(function (require, exports, module) {
276283
CodeHintList.prototype.isHandlingKeyCode = function (keyCode) {
277284
return (keyCode === KeyEvent.DOM_VK_UP || keyCode === KeyEvent.DOM_VK_DOWN ||
278285
keyCode === KeyEvent.DOM_VK_PAGE_UP || keyCode === KeyEvent.DOM_VK_PAGE_DOWN ||
279-
keyCode === KeyEvent.DOM_VK_RETURN);
280-
286+
keyCode === KeyEvent.DOM_VK_RETURN ||
287+
(keyCode === KeyEvent.DOM_VK_TAB && this.insertHintOnTab));
281288
};
282289

283290
/**
@@ -368,7 +375,8 @@ define(function (require, exports, module) {
368375
} else if (keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
369376
_rotateSelection.call(this, _itemsPerPage());
370377
} else if (this.selectedIndex !== -1 &&
371-
(keyCode === KeyEvent.DOM_VK_RETURN)) {
378+
(keyCode === KeyEvent.DOM_VK_RETURN ||
379+
(keyCode === KeyEvent.DOM_VK_TAB && this.insertHintOnTab))) {
372380
// Trigger a click handler to commmit the selected item
373381
$(this.$hintMenu.find("li")[this.selectedIndex]).trigger("click");
374382
} else {

src/editor/CodeHintManager.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@
212212
* return {boolean}
213213
* Indicates whether the manager should follow hint insertion with an
214214
* explicit hint request.
215+
*
216+
*
217+
* # CodeHintProvider.insertHintOnTab
218+
*
219+
* type {?boolean} insertHintOnTab
220+
* Indicates whether the CodeHintManager should request that the provider of
221+
* the current session insert the currently selected hint on tab key events,
222+
* or if instead a tab character should be inserted into the editor. If omitted,
223+
* the fallback behavior is determined by the CodeHintManager. The default
224+
* behavior is to insert a tab character, but this can be changed with the
225+
* CodeHintManager.setInsertHintOnTab() method.
215226
*/
216227

217228

@@ -237,6 +248,23 @@ define(function (require, exports, module) {
237248
deferredHints = null,
238249
keyDownEditor = null;
239250

251+
252+
var _insertHintOnTabDefault = false;
253+
254+
/**
255+
* Determines the default behavior of the CodeHintManager on tab key events.
256+
* setInsertHintOnTab(true) indicates that the currently selected code hint
257+
* should be inserted on tab key events. setInsertHintOnTab(false) indicates
258+
* that a tab character should be inserted into the editor on tab key events.
259+
* The default behavior can be overridden by individual providers.
260+
*
261+
* @param {boolean} Indicates whether providers should insert the currently
262+
* selected hint on tab key events.
263+
*/
264+
function setInsertHintOnTab(insertHintOnTab) {
265+
_insertHintOnTabDefault = insertHintOnTab;
266+
}
267+
240268
/**
241269
* Comparator to sort providers from high to low priority
242270
*/
@@ -439,9 +467,16 @@ define(function (require, exports, module) {
439467

440468
// If a provider is found, initialize the hint list and update it
441469
if (sessionProvider) {
470+
var insertHintOnTab;
471+
if (sessionProvider.insertHintOnTab !== undefined) {
472+
insertHintOnTab = sessionProvider.insertHintOnTab;
473+
} else {
474+
insertHintOnTab = _insertHintOnTabDefault;
475+
}
476+
442477
sessionEditor = editor;
443-
444-
hintList = new CodeHintList(sessionEditor);
478+
479+
hintList = new CodeHintList(sessionEditor, insertHintOnTab);
445480
hintList.onSelect(function (hint) {
446481
var restart = sessionProvider.insertHint(hint),
447482
previousEditor = sessionEditor;
@@ -589,4 +624,5 @@ define(function (require, exports, module) {
589624
exports.handleChange = handleChange;
590625
exports.registerHintProvider = registerHintProvider;
591626
exports.hasValidExclusion = hasValidExclusion;
627+
exports.setInsertHintOnTab = setInsertHintOnTab;
592628
});

0 commit comments

Comments
 (0)