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

Commit b2596ab

Browse files
committed
Merge pull request #9791 from MarcelGerber/max-code-hints
Add new pref maxCodeHints
2 parents c292e89 + 98ee9ae commit b2596ab

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/editor/CodeHintList.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ define(function (require, exports, module) {
2828
"use strict";
2929

3030
// Load dependent modules
31-
var Menus = require("command/Menus"),
31+
var KeyBindingManager = require("command/KeyBindingManager"),
32+
Menus = require("command/Menus"),
33+
KeyEvent = require("utils/KeyEvent"),
3234
StringUtils = require("utils/StringUtils"),
33-
PopUpManager = require("widgets/PopUpManager"),
35+
ValidationUtils = require("utils/ValidationUtils"),
3436
ViewUtils = require("utils/ViewUtils"),
35-
KeyBindingManager = require("command/KeyBindingManager"),
36-
KeyEvent = require("utils/KeyEvent");
37+
PopUpManager = require("widgets/PopUpManager");
3738

3839
var CodeHintListHTML = require("text!htmlContent/code-hint-list.html");
3940

@@ -42,8 +43,10 @@ define(function (require, exports, module) {
4243
*
4344
* @constructor
4445
* @param {Editor} editor
46+
* @param {boolean} insertHintOnTab Whether pressing tab inserts the selected hint
47+
* @param {number} maxResults Maximum hints displayed at once. Defaults to 1000
4548
*/
46-
function CodeHintList(editor, insertHintOnTab) {
49+
function CodeHintList(editor, insertHintOnTab, maxResults) {
4750

4851
/**
4952
* The list of hints to display
@@ -60,11 +63,14 @@ define(function (require, exports, module) {
6063
this.selectedIndex = -1;
6164

6265
/**
63-
* The maximum number of hints to display
66+
* The maximum number of hints to display. Can be overriden via maxCodeHints pref
6467
*
6568
* @type {number}
6669
*/
67-
this.maxResults = 999;
70+
this.maxResults = Math.min(
71+
(maxResults > 0 && ValidationUtils.isInteger(maxResults) && maxResults) || 1000,
72+
1000
73+
);
6874

6975
/**
7076
* Is the list currently open?
@@ -215,7 +221,7 @@ define(function (require, exports, module) {
215221
}
216222
} else {
217223
this.hints.some(function (item, index) {
218-
if (index > self.maxResults) {
224+
if (index >= self.maxResults) {
219225
return true;
220226
}
221227

src/editor/CodeHintManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ define(function (require, exports, module) {
254254

255255
PreferencesManager.definePreference("showCodeHints", "boolean", true);
256256
PreferencesManager.definePreference("insertHintOnTab", "boolean", false);
257+
PreferencesManager.definePreference("maxCodeHints", "integer", 50);
257258

258259
PreferencesManager.on("change", "showCodeHints", function () {
259260
codeHintsEnabled = PreferencesManager.get("showCodeHints");
@@ -484,7 +485,8 @@ define(function (require, exports, module) {
484485

485486
// If a provider is found, initialize the hint list and update it
486487
if (sessionProvider) {
487-
var insertHintOnTab;
488+
var insertHintOnTab,
489+
maxCodeHints = PreferencesManager.get("maxCodeHints");
488490
if (sessionProvider.insertHintOnTab !== undefined) {
489491
insertHintOnTab = sessionProvider.insertHintOnTab;
490492
} else {
@@ -493,7 +495,7 @@ define(function (require, exports, module) {
493495

494496
sessionEditor = editor;
495497

496-
hintList = new CodeHintList(sessionEditor, insertHintOnTab);
498+
hintList = new CodeHintList(sessionEditor, insertHintOnTab, maxCodeHints);
497499
hintList.onSelect(function (hint) {
498500
var restart = sessionProvider.insertHint(hint),
499501
previousEditor = sessionEditor;

src/utils/ValidationUtils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ define(function (require, exports, module) {
3333
* Used to validate whether type of unknown value is an integer.
3434
*
3535
* @param {*} value Value for which to validate its type
36-
* @return {boolean} true if value is an integer
36+
* @return {boolean} true if value is a finite integer
3737
*/
3838
function isInteger(value) {
3939
// Validate value is a number
@@ -42,9 +42,12 @@ define(function (require, exports, module) {
4242
}
4343

4444
// Validate number is an integer
45-
if (value > 0 && Math.floor(value) !== value) {
45+
if (Math.floor(value) !== value) {
4646
return false;
47-
} else if (value < 0 && Math.ceil(value) !== value) {
47+
}
48+
49+
// Validate number is finite
50+
if (!isFinite(value)) {
4851
return false;
4952
}
5053

0 commit comments

Comments
 (0)