Changeset 31688 in webkit


Ignore:
Timestamp:
Apr 7, 2008 1:01:54 PM (16 years ago)
Author:
timothy@apple.com
Message:

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.

Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r31687 r31688  
     12008-04-07  Timothy Hatcher  <timothy@apple.com>
     2
     3        When the WebInspector.currentFocusElement changes, move the caret
     4        selection to be inside the focused element. This makes sure the
     5        caret moves in and out of the console when the focus changes.
     6
     7        Reviewed by Adam Roben.
     8
     9        * page/inspector/TextPrompt.js:
     10        (TextPrompt.prototype.isCaretInsidePrompt): Just call isInsertionCaretInside.
     11        * page/inspector/inspector.js:
     12        (WebInspector.set currentFocusElement): Make a caret selection inside
     13        the focused element if there isn't a range selection and there isn't
     14        already a caret selection inside.
     15        * page/inspector/utilities.js:
     16        (Element.prototype.isInsertionCaretInside): Added. Tests if the
     17        selection is collapsed and is inside the element.
     18
    1192008-04-07  Brady Eidson  <beidson@apple.com>
    220
  • trunk/WebCore/page/inspector/TextPrompt.js

    r31648 r31688  
    263263    isCaretInsidePrompt: function()
    264264    {
    265         var selection = window.getSelection();
    266         if (!selection.rangeCount || !selection.isCollapsed)
    267             return false;
    268         var selectionRange = selection.getRangeAt(0);
    269         return selectionRange.startContainer === this.element || selectionRange.startContainer.isDescendant(this.element);
     265        return this.element.isInsertionCaretInside();
    270266    },
    271267
  • trunk/WebCore/page/inspector/inspector.js

    r31641 r31688  
    106106            if (this._currentFocusElement.focused)
    107107                this._currentFocusElement.focused();
     108
     109            // Make a caret selection inside the new element if there isn't a range selection and
     110            // there isn't already a caret selection inside.
     111            var selection = window.getSelection();
     112            if (selection.isCollapsed && !this._currentFocusElement.isInsertionCaretInside()) {
     113                var selectionRange = document.createRange();
     114                selectionRange.setStart(this._currentFocusElement, 0);
     115                selectionRange.setEnd(this._currentFocusElement, 0);
     116
     117                selection.removeAllRanges();
     118                selection.addRange(selectionRange);
     119            }
    108120        }
    109121    },
  • trunk/WebCore/page/inspector/utilities.js

    r31639 r31688  
    165165    while (this.firstChild)
    166166        this.removeChild(this.firstChild);       
     167}
     168
     169Element.prototype.isInsertionCaretInside = function()
     170{
     171    var selection = window.getSelection();
     172    if (!selection.rangeCount || !selection.isCollapsed)
     173        return false;
     174    var selectionRange = selection.getRangeAt(0);
     175    return selectionRange.startContainer === this || selectionRange.startContainer.isDescendant(this);
    167176}
    168177
Note: See TracChangeset for help on using the changeset viewer.