-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add new pref maxCodeHints #9791
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,13 @@ define(function (require, exports, module) { | |
"use strict"; | ||
|
||
// Load dependent modules | ||
var Menus = require("command/Menus"), | ||
var KeyBindingManager = require("command/KeyBindingManager"), | ||
Menus = require("command/Menus"), | ||
KeyEvent = require("utils/KeyEvent"), | ||
StringUtils = require("utils/StringUtils"), | ||
PopUpManager = require("widgets/PopUpManager"), | ||
ValidationUtils = require("utils/ValidationUtils"), | ||
ViewUtils = require("utils/ViewUtils"), | ||
KeyBindingManager = require("command/KeyBindingManager"), | ||
KeyEvent = require("utils/KeyEvent"); | ||
PopUpManager = require("widgets/PopUpManager"); | ||
|
||
var CodeHintListHTML = require("text!htmlContent/code-hint-list.html"); | ||
|
||
|
@@ -42,8 +43,10 @@ define(function (require, exports, module) { | |
* | ||
* @constructor | ||
* @param {Editor} editor | ||
* @param {boolean} insertHintOnTab Whether pressing tab inserts the selected hint | ||
* @param {number} maxResults Maximum hints displayed at once. Defaults to 1000 | ||
*/ | ||
function CodeHintList(editor, insertHintOnTab) { | ||
function CodeHintList(editor, insertHintOnTab, maxResults) { | ||
|
||
/** | ||
* The list of hints to display | ||
|
@@ -60,11 +63,14 @@ define(function (require, exports, module) { | |
this.selectedIndex = -1; | ||
|
||
/** | ||
* The maximum number of hints to display | ||
* The maximum number of hints to display. Can be overriden via maxCodeHints pref | ||
* | ||
* @type {number} | ||
*/ | ||
this.maxResults = 999; | ||
this.maxResults = Math.min( | ||
(maxResults > 0 && ValidationUtils.isInteger(maxResults) && maxResults) || 1000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the dense logic here a little hard to follow. It seems more clear if we did something like:
or
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems odd to me that the pref defaults to 50 but the API defaults to 1000. Any reason for the difference? We could still cap the arg at 1000 but have it default to 50 if unspecified -- the 2nd of my code suggestions above would leave the code still pretty easily understandable if we did that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, seems reasonable - feel free to open a PR. |
||
1000 | ||
); | ||
|
||
/** | ||
* Is the list currently open? | ||
|
@@ -215,7 +221,7 @@ define(function (require, exports, module) { | |
} | ||
} else { | ||
this.hints.some(function (item, index) { | ||
if (index > self.maxResults) { | ||
if (index >= self.maxResults) { | ||
return true; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ define(function (require, exports, module) { | |
* Used to validate whether type of unknown value is an integer. | ||
* | ||
* @param {*} value Value for which to validate its type | ||
* @return {boolean} true if value is an integer | ||
* @return {boolean} true if value is a finite integer | ||
*/ | ||
function isInteger(value) { | ||
// Validate value is a number | ||
|
@@ -42,9 +42,12 @@ define(function (require, exports, module) { | |
} | ||
|
||
// Validate number is an integer | ||
if (value > 0 && Math.floor(value) !== value) { | ||
if (Math.floor(value) !== value) { | ||
return false; | ||
} else if (value < 0 && Math.ceil(value) !== value) { | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following only works for positive integers, right? if (Math.floor(value) !== value) {
return false;
}
if (value > 0 && Math.floor(value) !== value) {
return false;
} else if (value < 0 && Math.ceil(value) !== value) {
return false;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind -- I can see that code works just as well. There's no need to correctly truncate any fraction -- just determine whether or not there is a fraction. |
||
|
||
// Validate number is finite | ||
if (!isFinite(value)) { | ||
return false; | ||
} | ||
|
||
|
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.
Need to add a
@param
formaxResults
. I can see that it's not part of your PR, but can you also add one forinsertHintOnTab
too?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.
Done.