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

Commit

Permalink
Add one more code hints extension api to let the provider decide on t…
Browse files Browse the repository at this point in the history
…he default initial selection. This fixes issue #2286
  • Loading branch information
RaymondLim committed Dec 6, 2012
1 parent 53c1d94 commit ea97d4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/editor/CodeHintManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ define(function (require, exports, module) {

if (count === 0) {
this.close();
} else {
} else if (this.currentProvider.wantInitialSelection()) {
// Select the first item in the list
this.setSelectedIndex(0);
}
Expand Down Expand Up @@ -243,6 +243,13 @@ define(function (require, exports, module) {

// Up arrow, down arrow and enter key are always handled here
if (event.type !== "keypress") {
// If we don't have a selection in the list, then just update the list and
// show it at the new location for Return and Tab keys.
if (this.selectedIndex === -1 && (keyCode === KeyEvent.DOM_VK_RETURN || keyCode === KeyEvent.DOM_VK_TAB)) {
this.updateQueryAndList();
return;
}

if (keyCode === KeyEvent.DOM_VK_RETURN || keyCode === KeyEvent.DOM_VK_TAB ||
keyCode === KeyEvent.DOM_VK_UP || keyCode === KeyEvent.DOM_VK_DOWN ||
keyCode === KeyEvent.DOM_VK_PAGE_UP || keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
Expand Down Expand Up @@ -497,7 +504,8 @@ define(function (require, exports, module) {
* @param {Object.< getQueryInfo: function(editor, cursor),
* search: function(string),
* handleSelect: function(string, Editor, cursor),
* shouldShowHintsOnKey: function(string)>}
* shouldShowHintsOnKey: function(string),
* wantInitialSelection: function()>}
*
* Parameter Details:
* - getQueryInfo - examines cursor location of editor and returns an object representing
Expand All @@ -509,6 +517,7 @@ define(function (require, exports, module) {
* position. It should return true by default to close the hint list, but if the code hint provider
* can return false if it wants to keep the hint list open and continue with a updated list.
* - shouldShowHintsOnKey - inspects the char code and returns true if it wants to show code hints on that key.
* - wantInitialSelection - return true if the provider wants to select the first hint item by default.
*
* @param {Array.<string>} modes An array of mode strings in which the provider can show code hints or "all"
* if it can show code hints in any mode.
Expand Down
16 changes: 16 additions & 0 deletions src/extensions/default/HTMLCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ define(function (require, exports, module) {
return key === "<";
};

/**
* Check whether to select the first item in the list by default
* @return {boolean} return true to highlight the first item.
*/
TagHints.prototype.wantInitialSelection = function () {
return true;
};

/**
* @constructor
*/
Expand Down Expand Up @@ -478,6 +486,14 @@ define(function (require, exports, module) {
return (key === " " || key === "'" || key === "\"" || key === "=");
};

/**
* Check whether to select the first item in the list by default
* @return {boolean} return true to highlight the first item.
*/
AttrHints.prototype.wantInitialSelection = function () {
return true;
};

var tagHints = new TagHints();
var attrHints = new AttrHints();
CodeHintManager.registerHintProvider(tagHints, ["html"], 0);
Expand Down

0 comments on commit ea97d4e

Please sign in to comment.