Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: Source/WebCore/inspector/front-end/TextPrompt.js

Issue 9131006: Revert 105252 - Merge 105140 - Web Inspector: [TextPrompt] Autocomplete adds unwanted text that's... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/963/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/inspector/front-end/StylesSidebarPane.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/inspector/front-end/TextPrompt.js
===================================================================
--- Source/WebCore/inspector/front-end/TextPrompt.js (revision 105498)
+++ Source/WebCore/inspector/front-end/TextPrompt.js (working copy)
@@ -137,7 +137,7 @@
set text(x)
{
- this._removeSuggestionAids();
+ this.clearAutoComplete(true);
if (!x) {
// Append a break element instead of setting textContent to make sure the selection is inside the prompt.
this._element.removeChildren();
@@ -186,26 +186,19 @@
WebInspector.markBeingEdited(this._element, false);
},
- _removeSuggestionAids: function()
- {
- this.clearAutoComplete();
- this.hideSuggestBox();
- },
-
_selectStart: function(event)
{
if (this._selectionTimeout)
clearTimeout(this._selectionTimeout);
- this._removeSuggestionAids();
+ this.clearAutoComplete();
function moveBackIfOutside()
{
delete this._selectionTimeout;
- if (!this.isCaretInsidePrompt() && window.getSelection().isCollapsed) {
+ if (!this.isCaretInsidePrompt() && window.getSelection().isCollapsed)
this.moveCaretToEndOfPrompt();
- this.autoCompleteSoon();
- }
+ this.autoCompleteSoon();
}
this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100);
@@ -233,37 +226,28 @@
case "Down":
handled = this.downKeyPressed(event);
break;
- case "PageUp":
- handled = this.pageUpKeyPressed(event);
- break;
- case "PageDown":
- handled = this.pageDownKeyPressed(event);
- break;
case "U+0009": // Tab
handled = this.tabKeyPressed(event);
break;
case "Enter":
handled = this.enterKeyPressed(event);
break;
- case "Left":
- case "Home":
- this._removeSuggestionAids();
- invokeDefault = false;
- break;
case "Right":
case "End":
- if (this.isCaretAtEndOfPrompt())
+ if (this.isSuggestBoxVisible() && this.isCaretAtEndOfPrompt())
+ handled = this._suggestBox.tabKeyPressed(event);
+ else {
handled = this.acceptAutoComplete();
- else
- this._removeSuggestionAids();
- invokeDefault = false;
+ if (!handled)
+ this.autoCompleteSoon();
+ }
break;
case "U+001B": // Esc
if (this.isSuggestBoxVisible()) {
this._suggestBox.hide();
handled = true;
+ break;
}
- break;
case "U+0020": // Space
if (this._suggestForceable && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
this.defaultKeyHandler(event, true);
@@ -291,13 +275,9 @@
acceptAutoComplete: function()
{
- var result = false;
if (this.isSuggestBoxVisible())
- result = this._suggestBox.acceptSuggestion();
- if (!result)
- result = this.acceptSuggestion();
-
- return result;
+ return this._suggestBox.acceptSuggestion();
+ return this.acceptSuggestion();
},
/**
@@ -368,7 +348,7 @@
shouldExit = true;
else if (!auto && !isEmptyInput && !selectionRange.commonAncestorContainer.isDescendant(this._element))
shouldExit = true;
- else if (auto && !force && !this.isCaretAtEndOfPrompt() && !this.isSuggestBoxVisible())
+ else if (auto && !this._suggestBox && !force && !this.isCaretAtEndOfPrompt())
shouldExit = true;
else if (!selection.isCollapsed)
shouldExit = true;
@@ -425,7 +405,7 @@
this._userEnteredText = fullWordRange.toString();
if (this._suggestBox)
- this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions, !this.isCaretAtEndOfPrompt());
+ this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions);
var wordPrefixLength = originalWordPrefixRange.toString().length;
@@ -472,27 +452,25 @@
}
if (auto) {
- if (this.isCaretAtEndOfPrompt()) {
- this._userEnteredRange.deleteContents();
- this._element.pruneEmptyTextNodes();
- var finalSelectionRange = document.createRange();
- var prefixText = completionText.substring(0, wordPrefixLength);
- var suffixText = completionText.substring(wordPrefixLength);
+ this._userEnteredRange.deleteContents();
+ this._element.pruneEmptyTextNodes();
+ var finalSelectionRange = document.createRange();
+ var prefixText = completionText.substring(0, wordPrefixLength);
+ var suffixText = completionText.substring(wordPrefixLength);
- var prefixTextNode = document.createTextNode(prefixText);
- fullWordRange.insertNode(prefixTextNode);
+ var prefixTextNode = document.createTextNode(prefixText);
+ fullWordRange.insertNode(prefixTextNode);
- this.autoCompleteElement = document.createElement("span");
- this.autoCompleteElement.className = "auto-complete-text";
- this.autoCompleteElement.textContent = suffixText;
+ this.autoCompleteElement = document.createElement("span");
+ this.autoCompleteElement.className = "auto-complete-text";
+ this.autoCompleteElement.textContent = suffixText;
- prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling);
+ prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling);
- finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
- finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
- selection.removeAllRanges();
- selection.addRange(finalSelectionRange);
- }
+ finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
+ finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
+ selection.removeAllRanges();
+ selection.addRange(finalSelectionRange);
} else
this.applySuggestion(completionText, completions.length > 1, originalWordPrefixRange);
},
@@ -587,7 +565,7 @@
var foundNextText = false;
while (node) {
if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) {
- if (foundNextText && (!this.autoCompleteElement || !this.autoCompleteElement.isAncestor(node)))
+ if (foundNextText)
return false;
foundNextText = true;
}
@@ -657,7 +635,10 @@
tabKeyPressed: function(event)
{
- // Just consume the key.
+ if (this.isSuggestBoxVisible())
+ return this._suggestBox.tabKeyPressed(event);
+
+ this.complete(false, false, event.shiftKey);
return true;
},
@@ -683,23 +664,7 @@
return this._suggestBox.downKeyPressed(event);
return false;
- },
-
- pageUpKeyPressed: function(event)
- {
- if (this.isSuggestBoxVisible())
- return this._suggestBox.pageUpKeyPressed(event);
-
- return false;
- },
-
- pageDownKeyPressed: function(event)
- {
- if (this.isSuggestBoxVisible())
- return this._suggestBox.pageDownKeyPressed(event);
-
- return false;
- },
+ }
}
WebInspector.TextPrompt.prototype.__proto__ = WebInspector.Object.prototype;
@@ -1022,59 +987,31 @@
return true;
},
- _onNextItem: function(event, isPageScroll)
+ _onNextItem: function(event)
{
var children = this.contentElement.childNodes;
if (!children.length)
return false;
- if (!this._selectedElement)
+ if (this._selectedElement)
+ this._selectedElement = this._selectedElement.nextSibling || this.contentElement.firstChild;
+ else
this._selectedElement = this.contentElement.firstChild;
- else {
- if (!isPageScroll)
- this._selectedElement = this._selectedElement.nextSibling || this.contentElement.firstChild;
- else {
- var candidate = this._selectedElement;
-
- for (var itemsLeft = this._rowCountPerViewport; itemsLeft; --itemsLeft) {
- if (candidate.nextSibling)
- candidate = candidate.nextSibling;
- else
- break;
- }
-
- this._selectedElement = candidate;
- }
- }
this._updateSelection();
this._applySuggestion(undefined, true);
return true;
},
- _onPreviousItem: function(event, isPageScroll)
+ _onPreviousItem: function(event)
{
var children = this.contentElement.childNodes;
if (!children.length)
return false;
- if (!this._selectedElement)
+ if (this._selectedElement)
+ this._selectedElement = this._selectedElement.previousSibling || this.contentElement.lastChild;
+ else
this._selectedElement = this.contentElement.lastChild;
- else {
- if (!isPageScroll)
- this._selectedElement = this._selectedElement.previousSibling || this.contentElement.lastChild;
- else {
- var candidate = this._selectedElement;
-
- for (var itemsLeft = this._rowCountPerViewport; itemsLeft; --itemsLeft) {
- if (candidate.previousSibling)
- candidate = candidate.previousSibling;
- else
- break;
- }
-
- this._selectedElement = candidate;
- }
- }
this._updateSelection();
this._applySuggestion(undefined, true);
return true;
@@ -1083,15 +1020,14 @@
/**
* @param {AnchorBox} anchorBox
* @param {Array.<string>=} completions
- * @param {boolean=} canShowForSingleItem
*/
- updateSuggestions: function(anchorBox, completions, canShowForSingleItem)
+ updateSuggestions: function(anchorBox, completions)
{
if (this._suggestTimeout) {
clearTimeout(this._suggestTimeout);
delete this._suggestTimeout;
}
- this._completionsReady(anchorBox, completions, canShowForSingleItem);
+ this._completionsReady(anchorBox, completions);
},
_onItemMouseDown: function(text, event)
@@ -1119,11 +1055,14 @@
return element;
},
- /**
- * @param {boolean=} canShowForSingleItem
- */
- _updateItems: function(items, canShowForSingleItem)
+ _updateItems: function(items)
{
+ var children = this.contentElement.children;
+ this._selectedIndex = Math.min(children.length - 1, this._selectedIndex);
+ var selectedItemText = this._selectedIndex >= 0 ? children[this._selectedIndex].textContent : null;
+ var itemIndex = 0;
+ var child = this.contentElement.firstChild;
+ var childText = child ? child.textContent : null;
this.contentElement.removeChildren();
var userEnteredText = this._textPrompt._userEnteredText;
@@ -1133,7 +1072,7 @@
this.contentElement.appendChild(currentItemElement);
}
- this._selectedElement = canShowForSingleItem ? this.contentElement.firstChild : null;
+ this._selectedElement = this.contentElement.firstChild;
this._updateSelection();
},
@@ -1151,41 +1090,21 @@
},
/**
+ * @param {AnchorBox} anchorBox
* @param {Array.<string>=} completions
- * @param {boolean=} canShowForSingleItem
*/
- _canShowBox: function(completions, canShowForSingleItem)
+ _completionsReady: function(anchorBox, completions)
{
- if (!completions || !completions.length)
- return false;
-
- if (completions.length > 1)
- return true;
-
- // Do not show a single suggestion if it is the same as user-entered prefix, even if allowed to show single-item suggest boxes.
- return canShowForSingleItem && completions[0] !== this._textPrompt._userEnteredText;
- },
-
- _rememberRowCountPerViewport: function()
- {
- if (!this.contentElement.firstChild)
+ if (!completions || !completions.length) {
+ this.hide()
return;
+ }
- this._rowCountPerViewport = Math.floor(this.containerElement.offsetHeight / this.contentElement.firstChild.offsetHeight);
- },
-
- /**
- * @param {AnchorBox} anchorBox
- * @param {Array.<string>=} completions
- * @param {boolean=} canShowForSingleItem
- */
- _completionsReady: function(anchorBox, completions, canShowForSingleItem)
- {
- if (this._canShowBox(completions, canShowForSingleItem)) {
- this._updateItems(completions, canShowForSingleItem);
- this._updateBoxPosition(anchorBox);
+ this._updateItems(completions);
+ this._updateBoxPosition(anchorBox);
+ if (this.contentElement.children.length && this.contentElement.children.length > 1) {
+ // Will not be shown if a sole suggestion is equal to the user input.
this._element.addStyleClass("visible");
- this._rememberRowCountPerViewport();
} else
this.hide();
},
@@ -1200,24 +1119,10 @@
return this._onNextItem(event);
},
- pageUpKeyPressed: function(event)
- {
- return this._onPreviousItem(event, true);
- },
-
- pageDownKeyPressed: function(event)
- {
- return this._onNextItem(event, true);
- },
-
enterKeyPressed: function(event)
{
- var hasSelectedItem = !!this._selectedElement;
this.acceptSuggestion();
-
- // Report the event as non-handled if there is no selected item,
- // to commit the input or handle it otherwise.
- return hasSelectedItem;
+ return true;
},
tabKeyPressed: function(event)
« no previous file with comments | « Source/WebCore/inspector/front-end/StylesSidebarPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698