Restore the user entered text when clearing the auto-completion.
[WebKit-https.git] / WebCore / page / inspector / TextPrompt.js
index 99ad77f..9625ca6 100644 (file)
@@ -110,6 +110,25 @@ WebInspector.TextPrompt.prototype = {
         if (this.autoCompleteElement.parentNode)
             this.autoCompleteElement.parentNode.removeChild(this.autoCompleteElement);
         delete this.autoCompleteElement;
+
+        if (!this._userEnteredRange || !this._userEnteredText)
+            return;
+
+        this._userEnteredRange.deleteContents();
+
+        var userTextNode = document.createTextNode(this._userEnteredText);
+        this._userEnteredRange.insertNode(userTextNode);           
+
+        var selectionRange = document.createRange();
+        selectionRange.setStart(userTextNode, this._userEnteredText.length);
+        selectionRange.setEnd(userTextNode, this._userEnteredText.length);
+
+        var selection = window.getSelection();
+        selection.removeAllRanges();
+        selection.addRange(selectionRange);
+
+        delete this._userEnteredRange;
+        delete this._userEnteredText;
     },
 
     autoCompleteSoon: function()
@@ -162,6 +181,9 @@ WebInspector.TextPrompt.prototype = {
 
         var wordPrefixLength = wordPrefixRange.toString().length;
 
+        this._userEnteredRange = fullWordRange;
+        this._userEnteredText = fullWordRange.toString();
+
         fullWordRange.deleteContents();
 
         var finalSelectionRange = document.createRange();