Commit 7e1bec54 authored by timothy@apple.com's avatar timothy@apple.com
Browse files

When the WebInspector.currentFocusElement changes, move the caret selection to...

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f65c9fae
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
......@@ -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()
......
......@@ -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);
}
}
},
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment