Restore the user entered text when clearing the auto-completion.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Apr 2008 21:13:38 +0000 (21:13 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Apr 2008 21:13:38 +0000 (21:13 +0000)
This is important when the user typed text that is a different
case than the completion. This has no affect on the Console, since
it matches completions case-sensitively. This is used in the up-coming
Database Query view for words like "SELECT" and "INSERT".

Reviewed by Adam Roben.

* page/inspector/TextPrompt.js:
(WebInspector.TextPrompt.prototype.clearAutoComplete): Restore the user typed
text in the original DOM range that complete() saved away.
(WebInspector.TextPrompt.prototype.complete): Store away the fullWordRange
and it's text content so clearAutoComplete can restore it.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31648 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/TextPrompt.js

index 28dafea..9051f4d 100644 (file)
@@ -1,5 +1,21 @@
 2008-04-04  Timothy Hatcher  <timothy@apple.com>
 
+        Restore the user entered text when clearing the auto-completion.
+        This is important when the user typed text that is a different
+        case than the completion. This has no affect on the Console, since
+        it matches completions case-sensitively. This is used in the up-coming
+        Database Query view for words like "SELECT" and "INSERT".
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/TextPrompt.js:
+        (WebInspector.TextPrompt.prototype.clearAutoComplete): Restore the user typed
+        text in the original DOM range that complete() saved away.
+        (WebInspector.TextPrompt.prototype.complete): Store away the fullWordRange
+        and it's text content so clearAutoComplete can restore it.
+
+2008-04-04  Timothy Hatcher  <timothy@apple.com>
+
         Don't trim whitespace when looking for the current match, this prevents
         tabbing through matches in the up-coming Database Query view.
 
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();