When the WebInspector.currentFocusElement changes, move the caret selection to be...
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Apr 2008 20:01:54 +0000 (20:01 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Apr 2008 20:01:54 +0000 (20:01 +0000)
Reviewed by Adam Roben.

* page/inspector/TextPrompt.js:
(TextPrompt.prototype.isCaretInsidePrompt): Just call isInsertionCaretInside.
* page/inspector/inspector.js:
(WebInspector.set currentFocusElement): Make a caret selection inside
the focused element if there isn't a range selection and there isn't
already a caret selection inside.
* page/inspector/utilities.js:
(Element.prototype.isInsertionCaretInside): Added. Tests if the
selection is collapsed and is inside the element.

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

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

index 7e92c7b..e7389e1 100644 (file)
@@ -1,3 +1,21 @@
+2008-04-07  Timothy Hatcher  <timothy@apple.com>
+
+        When the WebInspector.currentFocusElement changes, move the caret
+        selection to be inside the focused element. This makes sure the
+        caret moves in and out of the console when the focus changes.
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/TextPrompt.js:
+        (TextPrompt.prototype.isCaretInsidePrompt): Just call isInsertionCaretInside.
+        * page/inspector/inspector.js: 
+        (WebInspector.set currentFocusElement): Make a caret selection inside
+        the focused element if there isn't a range selection and there isn't
+        already a caret selection inside.
+        * page/inspector/utilities.js:
+        (Element.prototype.isInsertionCaretInside): Added. Tests if the
+        selection is collapsed and is inside the element.
+
 2008-04-07  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Tim Hatcher
index 9625ca6..264cb4c 100644 (file)
@@ -262,11 +262,7 @@ WebInspector.TextPrompt.prototype = {
 
     isCaretInsidePrompt: function()
     {
-        var selection = window.getSelection();
-        if (!selection.rangeCount || !selection.isCollapsed)
-            return false;
-        var selectionRange = selection.getRangeAt(0);
-        return selectionRange.startContainer === this.element || selectionRange.startContainer.isDescendant(this.element);
+        return this.element.isInsertionCaretInside();
     },
 
     isCaretAtEndOfPrompt: function()
index ebeb7b9..5c86180 100644 (file)
@@ -105,6 +105,18 @@ var WebInspector = {
                 this._currentFocusElement.focus();
             if (this._currentFocusElement.focused)
                 this._currentFocusElement.focused();
+
+            // Make a caret selection inside the new element if there isn't a range selection and
+            // there isn't already a caret selection inside.
+            var selection = window.getSelection();
+            if (selection.isCollapsed && !this._currentFocusElement.isInsertionCaretInside()) {
+                var selectionRange = document.createRange();
+                selectionRange.setStart(this._currentFocusElement, 0);
+                selectionRange.setEnd(this._currentFocusElement, 0);
+
+                selection.removeAllRanges();
+                selection.addRange(selectionRange);
+            }
         }
     },
 
index 46dc526..00b4e3e 100644 (file)
@@ -166,6 +166,15 @@ Element.prototype.removeChildren = function()
         this.removeChild(this.firstChild);        
 }
 
+Element.prototype.isInsertionCaretInside = function()
+{
+    var selection = window.getSelection();
+    if (!selection.rangeCount || !selection.isCollapsed)
+        return false;
+    var selectionRange = selection.getRangeAt(0);
+    return selectionRange.startContainer === this || selectionRange.startContainer.isDescendant(this);
+}
+
 Element.prototype.__defineGetter__("totalOffsetLeft", function() {
     var total = 0;
     for (var element = this; element; element = element.offsetParent)