WebCore:

2008-11-21  Justin Garcia  <justin.garcia@apple.com>

        Reviewed by Darin Adler.

        <rdar://problem/5381788> Match NSTextView editing behavior at the end of hyperlink text
        
        Change link editing behavior to match TextEdit and MS Word when editing before and after 
        a link (Pages has two caret positions at link boundaries, Thunderbird and FF behave like we 
        used to, so it's difficult to get out of link editing mode):
        When inserting before or after a link, always insert content outside of the link.  This
        makes it impossible to get stuck in link editing mode, while making it slightly more 
        difficult to edit link labels.  WebKit editors that care about this can add UI for editing 
        link labels, like GMail and GoogleDocs have done.  We never actually had any bugs complaining
        about how it was difficult to edit link labels at the start/end, the code was just introduced 
        with another bug fix without much thought.
        
        Don't remember removed links anymore, no other editor does this and it made it 
        difficult/impossible to get out of link editing mode.  This code was added to fix
        <rdar://problem/4069359>, which is fixed instead by removing the styles from an 
        enclosing anchor element from those styles that we remember when we delete content.

        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary):
        * editing/CompositeEditCommand.h:
        * editing/DeleteSelectionCommand.cpp:
        (WebCore::removeEnclosingAnchorStyle):
        (WebCore::DeleteSelectionCommand::saveTypingStyleState):
        (WebCore::DeleteSelectionCommand::doApply):
        * editing/DeleteSelectionCommand.h:
        * editing/EditCommand.cpp:
        (WebCore::EditCommand::apply):
        * editing/Editor.cpp:
        (WebCore::Editor::appliedEditing):
        * editing/InsertTextCommand.cpp:
        (WebCore::InsertTextCommand::prepareForTextInsertion):
        (WebCore::InsertTextCommand::input):
        * editing/RemoveFormatCommand.cpp:
        (WebCore::RemoveFormatCommand::doApply):
        * editing/SelectionController.cpp:
        (WebCore::SelectionController::setSelection):
        * editing/SelectionController.h:

LayoutTests:

2008-11-21  Justin Garcia  <justin.garcia@apple.com>

        Reviewed by Darin Adler.
        
        <rdar://problem/5381788> Match NSTextView editing behavior at the end of hyperlink text
        
        Removed tests for behaviors that we're no longer interested in:
        * editing/deleting/delete-link-1.html: Removed.
        * platform/mac/editing/deleting/delete-link-1-expected.checksum: Removed.
        * platform/mac/editing/deleting/delete-link-1-expected.png: Removed.
        * platform/mac/editing/deleting/delete-link-1-expected.txt: Removed.
        * editing/execCommand/19653-4-expected.txt: Removed.
        * editing/execCommand/19653-4.html: Removed.
        
        Reflects new behavior (don't remember removed anchors):
        * platform/mac/editing/deleting/5168598-expected.txt:
        
        Reflects new behavior.  Also made this test cross-platform:
        * editing/inserting/insert-before-link-1-expected.txt: Added.
        * editing/inserting/insert-before-link-1.html:
        * platform/mac/editing/inserting/insert-before-link-1-expected.checksum: Removed.
        * platform/mac/editing/inserting/insert-before-link-1-expected.png: Removed.
        * platform/mac/editing/inserting/insert-before-link-1-expected.txt: Removed.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a9c40a41
2008-11-21 Justin Garcia <justin.garcia@apple.com>
Reviewed by Darin Adler.
<rdar://problem/5381788> Match NSTextView editing behavior at the end of hyperlink text
Removed tests for behaviors that we're no longer interested in:
* editing/deleting/delete-link-1.html: Removed.
* platform/mac/editing/deleting/delete-link-1-expected.checksum: Removed.
* platform/mac/editing/deleting/delete-link-1-expected.png: Removed.
* platform/mac/editing/deleting/delete-link-1-expected.txt: Removed.
* editing/execCommand/19653-4-expected.txt: Removed.
* editing/execCommand/19653-4.html: Removed.
Reflects new behavior (don't remember removed anchors):
* platform/mac/editing/deleting/5168598-expected.txt:
Reflects new behavior. Also made this test cross-platform:
* editing/inserting/insert-before-link-1-expected.txt: Added.
* editing/inserting/insert-before-link-1.html:
* platform/mac/editing/inserting/insert-before-link-1-expected.checksum: Removed.
* platform/mac/editing/inserting/insert-before-link-1-expected.png: Removed.
* platform/mac/editing/inserting/insert-before-link-1-expected.txt: Removed.
2008-11-21 Simon Fraser <simon.fraser@apple.com>
Reviewed by Darin Adler
......
<p>This tests link deletion. After deleting a link, subsequent text should be inserted into a link.</p>
<div id="div" contenteditable="true">Hello <a id="link" href="http://www.google.com/">b</a> World</div>
<ol id="console"></ol>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function shouldBe(expected, actual) {
if (expected != actual)
log("Failure. Expected: " + expected + ", Actual: " + actual);
else
log("Passed");
}
if (window.layoutTestController)
layoutTestController.dumpEditingCallbacks();
var div = document.getElementById("div");
var sel = window.getSelection();
sel.setPosition(div, 0);
sel.modify("move", "forward", "word");
sel.modify("move", "forward", "word");
sel.modify("extend", "backward", "character");
document.execCommand("Delete");
document.execCommand("InsertText", false, "this text should be in a link");
var link = document.getElementById("link");
if (link)
shouldBe(link.href, "http://www.google.com/");
else
log("Failure, the link wasn't reinserted, or it had a different id.");
</script>
\ No newline at end of file
This tests to make sure that a deleted anchor is restored when even brand new TypingCommand is created after it is removed. The text below should be in an anchor.
<font class="Apple-style-span" color="#0000EE"><span class="Apple-style-span" style="text-decoration: underline;"><a id="a" href="http://www.apple.com/">Anchor</a></span></font>
<div id="description1">This tests to make sure that a deleted anchor is restored when even brand new TypingCommand is created after it is removed. The text below should be in an anchor.</div>
<div id="edit1" contentEditable="true"><a id="a" href="http://www.apple.com/">Anchor</a></div>
<script>
if (window.layoutTestController)
window.layoutTestController.dumpAsText();
a = document.getElementById("a");
window.getSelection().setBaseAndExtent(a, 0, a, a.childNodes.length);
document.execCommand("Cut");
document.execCommand("InsertText", false, "Anchor");
if (window.layoutTestController)
document.body.innerText = document.getElementById("description1").innerText + "\n" + edit1.innerHTML;
</script>
This tests insertion before/after links. Text should always be inserted at the start or end of a link should be inserted outside of it.
this&nbsp;text&nbsp;should&nbsp;not&nbsp;be&nbsp;in&nbsp;a&nbsp;link<a id="link" href="http://www.google.com/">this should</a>this&nbsp;should&nbsp;not <a href="http://www.google.com/">this should</a>this&nbsp;should&nbsp;not
<p>This tests insertion before/after links in certain situations. Inserting before a link should always put the text outside the link unless insertion is happening at the start of a paragraph. Inserting after should always insert inside the link, unless insertion is happening at the end of the document.</p>
<div id="div" contenteditable="true"><a id="link" href="http://www.google.com/">link.</a> This <a href="http://www.google.com/">This should.</a></div>
<div id="description">This tests insertion before/after links. Text should always be inserted at the start or end of a link should be inserted outside of it.</div>
<div id="edit" contenteditable="true"><a id="link" href="http://www.google.com/">this should</a> <a href="http://www.google.com/">this should</a></div>
<script>
if (window.layoutTestController)
layoutTestController.dumpEditingCallbacks();
window.layoutTestController.dumpAsText();
var div = document.getElementById("div");
var edit = document.getElementById("edit");
var sel = window.getSelection();
sel.setPosition(div, 0);
sel.setPosition(edit, 0);
document.execCommand("InsertText", false, "This text should be in a ");
document.execCommand("InsertText", false, "this text should not be in a link");
sel.modify("move", "forward", "word");
sel.modify("move", "forward", "word");
document.execCommand("InsertText", false, " should not.");
document.execCommand("InsertText", false, "this should not");
sel.modify("move", "forward", "line");
sel.modify("move", "forward", "paragraphBoundary");
document.execCommand("InsertText", false, " This should not.");
document.execCommand("InsertText", false, "this should not");
if (window.layoutTestController)
document.body.innerText = document.getElementById("description").innerText + "\n\n" + edit.innerHTML;
</script>
\ No newline at end of file
......@@ -18,7 +18,5 @@ layer at (0,0) size 800x600
RenderText {#text} at (0,0) size 0x0
layer at (13,83) size 142x13
RenderBlock {DIV} at (3,3) size 142x13
RenderInline {FONT} at (0,0) size 0x13
RenderInline {SPAN} at (0,0) size 0x13
RenderBR {BR} at (1,0) size 0x13
caret: position 0 of child 0 {BR} of child 0 {SPAN} of child 0 {FONT} of child 0 {DIV} of child 3 {INPUT} of child 0 {BODY} of child 0 {HTML} of document
RenderBR {BR} at (1,0) size 0x13
caret: position 0 of child 0 {BR} of child 0 {DIV} of child 3 {INPUT} of child 0 {BODY} of child 0 {HTML} of document
f774b5e7d9f28ab38dcbbaf38525b32a
\ No newline at end of file
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldDeleteDOMRange:range from 0 of #text > A > DIV > BODY > HTML > #document to 1 of #text > A > DIV > BODY > HTML > #document
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document toDOMRange:range from 29 of #text > A > DIV > BODY > HTML > #document to 29 of #text > A > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x576
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 569x18
text run at (0,0) width 149: "This tests link deletion. "
text run at (149,0) width 420: "After deleting a link, subsequent text should be inserted into a link."
RenderBlock {DIV} at (0,34) size 784x18
RenderText {#text} at (0,0) size 39x18
text run at (0,0) width 39: "Hello "
RenderInline {A} at (0,0) size 169x18 [color=#0000EE]
RenderText {#text} at (39,0) size 169x18
text run at (39,0) width 169: "this text should be in a link"
RenderText {#text} at (208,0) size 44x18
text run at (208,0) width 44: " World"
RenderBlock {OL} at (0,68) size 784x18
RenderListItem {LI} at (40,0) size 744x18
RenderListMarker at (-20,0) size 16x18: "1"
RenderText {#text} at (0,0) size 43x18
text run at (0,0) width 43: "Passed"
caret: position 29 of child 0 {#text} of child 1 {A} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 25 of #text > A > DIV > BODY > HTML > #document to 25 of #text > A > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 5 of #text > DIV > BODY > HTML > #document to 5 of #text > DIV > BODY > HTML > #document toDOMRange:range from 17 of #text > DIV > BODY > HTML > #document to 17 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 12 of #text > A > DIV > BODY > HTML > #document to 12 of #text > A > DIV > BODY > HTML > #document toDOMRange:range from 17 of #text > DIV > BODY > HTML > #document to 17 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {P} at (0,0) size 784x54
RenderText {#text} at (0,0) size 782x54
text run at (0,0) width 360: "This tests insertion before/after links in certain situations. "
text run at (360,0) width 406: "Inserting before a link should always put the text outside the link"
text run at (0,18) width 352: "unless insertion is happening at the start of a paragraph. "
text run at (352,18) width 430: "Inserting after should always insert inside the link, unless insertion is"
text run at (0,36) width 241: "happening at the end of the document."
RenderBlock {DIV} at (0,70) size 784x18
RenderInline {A} at (0,0) size 179x18 [color=#0000EE]
RenderText {#text} at (0,0) size 179x18
text run at (0,0) width 179: "This text should be in a link."
RenderText {#text} at (179,0) size 110x18
text run at (179,0) width 110: " This should not. "
RenderInline {A} at (0,0) size 78x18 [color=#0000EE]
RenderText {#text} at (289,0) size 78x18
text run at (289,0) width 78: "This should."
RenderText {#text} at (367,0) size 106x18
text run at (367,0) width 106: " This should not."
caret: position 17 of child 3 {#text} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
2008-11-21 Justin Garcia <justin.garcia@apple.com>
Reviewed by Darin Adler.
<rdar://problem/5381788> Match NSTextView editing behavior at the end of hyperlink text
Change link editing behavior to match TextEdit and MS Word when editing before and after
a link (Pages has two caret positions at link boundaries, Thunderbird and FF behave like we
used to, so it's difficult to get out of link editing mode):
When inserting before or after a link, always insert content outside of the link. This
makes it impossible to get stuck in link editing mode, while making it slightly more
difficult to edit link labels. WebKit editors that care about this can add UI for editing
link labels, like GMail and GoogleDocs have done. We never actually had any bugs complaining
about how it was difficult to edit link labels at the start/end, the code was just introduced
with another bug fix without much thought.
Don't remember removed links anymore, no other editor does this and it made it
difficult/impossible to get out of link editing mode. This code was added to fix
<rdar://problem/4069359>, which is fixed instead by removing the styles from an
enclosing anchor element from those styles that we remember when we delete content.
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary):
* editing/CompositeEditCommand.h:
* editing/DeleteSelectionCommand.cpp:
(WebCore::removeEnclosingAnchorStyle):
(WebCore::DeleteSelectionCommand::saveTypingStyleState):
(WebCore::DeleteSelectionCommand::doApply):
* editing/DeleteSelectionCommand.h:
* editing/EditCommand.cpp:
(WebCore::EditCommand::apply):
* editing/Editor.cpp:
(WebCore::Editor::appliedEditing):
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::prepareForTextInsertion):
(WebCore::InsertTextCommand::input):
* editing/RemoveFormatCommand.cpp:
(WebCore::RemoveFormatCommand::doApply):
* editing/SelectionController.cpp:
(WebCore::SelectionController::setSelection):
* editing/SelectionController.h:
2008-11-21 Alice Liu <alice.liu@apple.com>
Rubber-stamped by Dan Bernstein.
......@@ -957,7 +957,7 @@ bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph()
// that anchor, as in NSTextView.
// FIXME: This is only an approximation of NSTextViews insertion behavior, which varies depending on how
// the caret was made.
Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Position& original, bool alwaysAvoidAnchors)
Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Position& original)
{
if (original.isNull())
return original;
......@@ -971,7 +971,7 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
VisiblePosition lastInAnchor(Position(enclosingAnchor, maxDeepOffset(enclosingAnchor)));
// If visually just after the anchor, insert *inside* the anchor unless it's the last
// VisiblePosition in the document, to match NSTextView.
if (visiblePos == lastInAnchor && (isEndOfDocument(visiblePos) || alwaysAvoidAnchors)) {
if (visiblePos == lastInAnchor) {
// Make sure anchors are pushed down before avoiding them so that we don't
// also avoid structural elements like lists and blocks (5142012).
if (original.node() != enclosingAnchor && original.node()->parentNode() != enclosingAnchor) {
......@@ -990,7 +990,7 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
}
// If visually just before an anchor, insert *outside* the anchor unless it's the first
// VisiblePosition in a paragraph, to match NSTextView.
if (visiblePos == firstInAnchor && (!isStartOfParagraph(visiblePos) || alwaysAvoidAnchors)) {
if (visiblePos == firstInAnchor) {
// Make sure anchors are pushed down before avoiding them so that we don't
// also avoid structural elements like lists and blocks (5142012).
if (original.node() != enclosingAnchor && original.node()->parentNode() != enclosingAnchor) {
......
......@@ -103,7 +103,7 @@ protected:
bool breakOutOfEmptyListItem();
bool breakOutOfEmptyMailBlockquotedParagraph();
Position positionAvoidingSpecialElementBoundary(const Position&, bool alwaysAvoidAnchors = true);
Position positionAvoidingSpecialElementBoundary(const Position&);
PassRefPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncestor = false);
......
......@@ -247,6 +247,18 @@ void DeleteSelectionCommand::initializePositionData()
m_endBlock = enclosingNodeOfType(rangeCompliantEquivalent(m_upstreamEnd), &isBlock, false);
}
static void removeEnclosingAnchorStyle(CSSMutableStyleDeclaration* style, const Position& position)
{
Node* enclosingAnchor = enclosingAnchorElement(position);
if (!enclosingAnchor || !enclosingAnchor->parentNode())
return;
RefPtr<CSSMutableStyleDeclaration> parentStyle = Position(enclosingAnchor->parentNode(), 0).computedStyle()->copyInheritableProperties();
RefPtr<CSSMutableStyleDeclaration> anchorStyle = Position(enclosingAnchor, 0).computedStyle()->copyInheritableProperties();
parentStyle->diff(anchorStyle.get());
anchorStyle->diff(style);
}
void DeleteSelectionCommand::saveTypingStyleState()
{
// A common case is deleting characters that are all from the same text node. In
......@@ -263,6 +275,8 @@ void DeleteSelectionCommand::saveTypingStyleState()
RefPtr<CSSComputedStyleDeclaration> computedStyle = positionBeforeTabSpan(m_selectionToDelete.start()).computedStyle();
m_typingStyle = computedStyle->copyInheritableProperties();
removeEnclosingAnchorStyle(m_typingStyle.get(), m_selectionToDelete.start());
// If we're deleting into a Mail blockquote, save the style at end() instead of start()
// We'll use this later in computeTypingStyleAfterDelete if we end up outside of a Mail blockquote
if (nearestMailBlockquote(m_selectionToDelete.start().node())) {
......@@ -692,31 +706,6 @@ void DeleteSelectionCommand::clearTransientState()
m_trailingWhitespace.clear();
}
void DeleteSelectionCommand::saveFullySelectedAnchor()
{
// If deleting an anchor element, save it away so that it can be restored
// when the user begins entering text.
Position start = m_selectionToDelete.start();
Node* startAnchor = enclosingNodeWithTag(start.downstream(), aTag);
if (!startAnchor)
return;
Position end = m_selectionToDelete.end();
Node* endAnchor = enclosingNodeWithTag(end.upstream(), aTag);
if (startAnchor != endAnchor)
return;
VisiblePosition visibleStart(m_selectionToDelete.visibleStart());
VisiblePosition visibleEnd(m_selectionToDelete.visibleEnd());
Node* beforeStartAnchor = enclosingNodeWithTag(visibleStart.previous().deepEquivalent().downstream(), aTag);
Node* afterEndAnchor = enclosingNodeWithTag(visibleEnd.next().deepEquivalent().upstream(), aTag);
if (startAnchor && startAnchor == endAnchor && startAnchor != beforeStartAnchor && endAnchor != afterEndAnchor)
document()->frame()->editor()->setRemovedAnchor(startAnchor->cloneNode(false));
}
void DeleteSelectionCommand::doApply()
{
// If selection has not been set to a custom selection when the command was created,
......@@ -762,8 +751,6 @@ void DeleteSelectionCommand::doApply()
saveTypingStyleState();
saveFullySelectedAnchor();
// deleting just a BR is handled specially, at least because we do not
// want to replace it with a placeholder BR!
if (handleSpecialCaseBRDelete()) {
......
......@@ -53,7 +53,6 @@ private:
void initializeStartEnd(Position&, Position&);
void initializePositionData();
void saveTypingStyleState();
void saveFullySelectedAnchor();
void insertPlaceholderForAncestorBlockContent();
bool handleSpecialCaseBRDelete();
void handleGeneralDelete();
......
......@@ -86,13 +86,6 @@ void EditCommand::apply()
// use them perform one if one is necessary (like for the creation of VisiblePositions).
if (!m_parent)
updateLayout();
// All high level commands, and all commands that a TypingCommand spawns, except for
// text insertions, which should restore a removed anchor, should clear it.
if (!m_parent && !isTypingCommand())
frame->editor()->setRemovedAnchor(0);
if (m_parent && m_parent->isTypingCommand() && !isInsertTextCommand())
frame->editor()->setRemovedAnchor(0);
DeleteButtonController* deleteButtonController = frame->editor()->deleteButtonController();
deleteButtonController->disable();
......
......@@ -869,7 +869,7 @@ void Editor::appliedEditing(PassRefPtr<EditCommand> cmd)
// because there is work that it must do in this situation.
// The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
// See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
// Don't clear the typing style or removedAnchor with this selection change. We do those things elsewhere if necessary.
// Don't clear the typing style with this selection change. We do those things elsewhere if necessary.
if (newSelection == m_frame->selection()->selection() || m_frame->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, false, false);
......
......@@ -56,13 +56,6 @@ void InsertTextCommand::doApply()
Position InsertTextCommand::prepareForTextInsertion(const Position& p)
{
Position pos = p;
// If an anchor was removed and the selection hasn't changed, we restore it.
RefPtr<Node> anchor = document()->frame()->editor()->removedAnchor();
if (anchor) {
insertNodeAt(anchor.get(), pos);
document()->frame()->editor()->setRemovedAnchor(0);
pos = Position(anchor.get(), 0);
}
// Prepare for text input by looking at the specified position.
// It may be necessary to insert a text node to receive characters.
if (!pos.node()->isTextNode()) {
......@@ -148,10 +141,7 @@ void InsertTextCommand::input(const String& originalText, bool selectInsertedTex
if (!startPosition.isCandidate())
startPosition = startPosition.downstream();
// FIXME: This typing around anchor behavior doesn't exactly match TextEdit. In TextEdit,
// you won't be placed inside a link when typing after it if you've just placed the caret
// there with the mouse.
startPosition = positionAvoidingSpecialElementBoundary(startPosition, false);
startPosition = positionAvoidingSpecialElementBoundary(startPosition);
Position endPosition;
......
......@@ -71,9 +71,6 @@ void RemoveFormatCommand::doApply()
if (string.isEmpty())
return;
// Normally, deleting a fully selected anchor and then inserting text will re-create
// the removed anchor, but we don't want that behavior here.
frame->editor()->setRemovedAnchor(0);
// Insert the content with the default style.
// See <rdar://problem/5794382> RemoveFormat doesn't always reset text alignment
frame->setTypingStyle(defaultStyle.get());
......
......@@ -97,7 +97,7 @@ void SelectionController::moveTo(const Position &base, const Position &extent, E
setSelection(Selection(base, extent, affinity), true, true, userTriggered);
}
void SelectionController::setSelection(const Selection& s, bool closeTyping, bool clearTypingStyleAndRemovedAnchor, bool userTriggered)
void SelectionController::setSelection(const Selection& s, bool closeTyping, bool clearTypingStyle, bool userTriggered)
{
if (m_isDragCaretController) {
invalidateCaretRect();
......@@ -112,17 +112,15 @@ void SelectionController::setSelection(const Selection& s, bool closeTyping, boo
}
if (s.base().node() && s.base().node()->document() != m_frame->document()) {
s.base().node()->document()->frame()->selection()->setSelection(s, closeTyping, clearTypingStyleAndRemovedAnchor, userTriggered);
s.base().node()->document()->frame()->selection()->setSelection(s, closeTyping, clearTypingStyle, userTriggered);
return;
}
if (closeTyping)
TypingCommand::closeTyping(m_frame->editor()->lastEditCommand());
if (clearTypingStyleAndRemovedAnchor) {
if (clearTypingStyle)
m_frame->clearTypingStyle();
m_frame->editor()->setRemovedAnchor(0);
}
if (m_sel == s)
return;
......
......@@ -57,7 +57,7 @@ public:
void moveTo(const Position&, const Position&, EAffinity, bool userTriggered = false);
const Selection& selection() const { return m_sel; }
void setSelection(const Selection&, bool closeTyping = true, bool clearTypingStyleAndRemovedAnchor = true, bool userTriggered = false);
void setSelection(const Selection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false);
bool setSelectedRange(Range*, EAffinity, bool closeTyping);
void selectAll();
void clear();
......
Markdown is supported
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