Skip to content

Commit

Permalink
DevTools: include history items in the console suggest box.
Browse files Browse the repository at this point in the history
Review URL: https://codereview.chromium.org/1569353003

Cr-Commit-Position: refs/heads/master@{#368978}
  • Loading branch information
pavelfeldman authored and Commit bot committed Jan 12, 2016
1 parent 9844585 commit 4feb920
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
7 changes: 4 additions & 3 deletions front_end/ui/SuggestBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ WebInspector.SuggestBox.prototype = {
if (!this.visible() || !this._selectedElement)
return false;

var suggestion = this._selectedElement.textContent;
var suggestion = this._selectedElement.__fullValue;
if (!suggestion)
return false;

Expand Down Expand Up @@ -247,10 +247,11 @@ WebInspector.SuggestBox.prototype = {
element.tabIndex = -1;
if (prefix && prefix.length && !text.indexOf(prefix)) {
element.createChild("span", "prefix").textContent = prefix;
element.createChild("span", "suffix").textContent = text.substring(prefix.length);
element.createChild("span", "suffix").textContent = text.substring(prefix.length).trimEnd(50);
} else {
element.createChild("span", "suffix").textContent = text;
element.createChild("span", "suffix").textContent = text.trimEnd(50);
}
element.__fullValue = text;
element.createChild("span", "spacer");
element.addEventListener("mousedown", this._onItemMouseDown.bind(this), false);
return element;
Expand Down
58 changes: 48 additions & 10 deletions front_end/ui/TextPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ WebInspector.TextPrompt.prototype = {

var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, this._completionStopCharacters, this._element, "backward");
this._waitingForCompletions = true;
this._loadCompletions(/** @type {!Element} */ (this._proxyElement), this.text(), selectionRange.startOffset, wordPrefixRange, force || false, this._completionsReady.bind(this, selection, wordPrefixRange, !!reverse));
this._loadCompletions(/** @type {!Element} */ (this._proxyElement), this.text(), selectionRange.startOffset, wordPrefixRange, force || false, this._completionsReady.bind(this, selection, wordPrefixRange, !!reverse, !!force));
},

disableDefaultSuggestionForEmptyInput: function()
Expand Down Expand Up @@ -466,19 +466,42 @@ WebInspector.TextPrompt.prototype = {
return document.createRange();
},

/**
* @param {string} prefix
* @return {!Array.<string>}
*/
additionalCompletions: function(prefix)
{
return [];
},

/**
* @param {!Selection} selection
* @param {!Range} originalWordPrefixRange
* @param {boolean} reverse
* @param {boolean} force
* @param {!Array.<string>} completions
* @param {number=} selectedIndex
*/
_completionsReady: function(selection, originalWordPrefixRange, reverse, completions, selectedIndex)
_completionsReady: function(selection, originalWordPrefixRange, reverse, force, completions, selectedIndex)
{
var prefix = originalWordPrefixRange.toString();
if (prefix || force) {
if (prefix)
completions = completions.concat(this.additionalCompletions(prefix));
else
completions = this.additionalCompletions(prefix).concat(completions);
}

// Filter out dupes.
var store = new Set();
completions = completions.filter(item => !store.has(item) && !!store.add(item));

if (!this._waitingForCompletions || !completions.length) {
this.hideSuggestBox();
return;
}

delete this._waitingForCompletions;

var selectionRange = selection.getRangeAt(0);
Expand All @@ -487,7 +510,7 @@ WebInspector.TextPrompt.prototype = {
fullWordRange.setStart(originalWordPrefixRange.startContainer, originalWordPrefixRange.startOffset);
fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffset);

if (originalWordPrefixRange.toString() + selectionRange.toString() !== fullWordRange.toString())
if (prefix + selectionRange.toString() !== fullWordRange.toString())
return;

selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.text()) ? -1 : (selectedIndex || 0);
Expand Down Expand Up @@ -555,15 +578,10 @@ WebInspector.TextPrompt.prototype = {
/**
* @param {string} completionText
* @param {boolean=} isIntermediateSuggestion
* @param {!Range=} originalPrefixRange
*/
_applySuggestion: function(completionText, isIntermediateSuggestion, originalPrefixRange)
_applySuggestion: function(completionText, isIntermediateSuggestion)
{
var wordPrefixLength;
if (originalPrefixRange)
wordPrefixLength = originalPrefixRange.toString().length;
else
wordPrefixLength = this._userEnteredText ? this._userEnteredText.length : 0;
var wordPrefixLength = this._userEnteredText ? this._userEnteredText.length : 0;

this._userEnteredRange.deleteContents();
this._element.normalize();
Expand Down Expand Up @@ -803,6 +821,26 @@ WebInspector.TextPromptWithHistory.prototype = {
return this._data;
},

/**
* @override
* @param {string} prefix
* @return {!Array.<string>}
*/
additionalCompletions: function(prefix)
{
if (!this.isCaretAtEndOfPrompt())
return [];
var result = [];
var text = this.text();
for (var i = this._data.length - 1; i >= 0 && result.length < 50; --i) {
var item = this._data[i];
if (!item.startsWith(text))
continue;
result.push(item.substring(text.length - prefix.length));
}
return result;
},

/**
* @param {!Array.<string>} data
*/
Expand Down

0 comments on commit 4feb920

Please sign in to comment.