diff options
author | Steve Block <steveblock@google.com> | 2011-05-18 13:36:51 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-24 15:38:28 +0100 |
commit | 2fc2651226baac27029e38c9d6ef883fa32084db (patch) | |
tree | e396d4bf89dcce6ed02071be66212495b1df1dec /Source/WebCore/editing/MoveSelectionCommand.cpp | |
parent | b3725cedeb43722b3b175aaeff70552e562d2c94 (diff) | |
download | external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.zip external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.gz external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.bz2 |
Merge WebKit at r78450: Initial merge by git.
Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1
Diffstat (limited to 'Source/WebCore/editing/MoveSelectionCommand.cpp')
-rw-r--r-- | Source/WebCore/editing/MoveSelectionCommand.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/Source/WebCore/editing/MoveSelectionCommand.cpp b/Source/WebCore/editing/MoveSelectionCommand.cpp index 3a1cae0..0f23b29 100644 --- a/Source/WebCore/editing/MoveSelectionCommand.cpp +++ b/Source/WebCore/editing/MoveSelectionCommand.cpp @@ -39,25 +39,21 @@ MoveSelectionCommand::MoveSelectionCommand(PassRefPtr<DocumentFragment> fragment void MoveSelectionCommand::doApply() { - VisibleSelection selection = endingSelection(); - ASSERT(selection.isNonOrphanedRange()); + ASSERT(endingSelection().isNonOrphanedRange()); Position pos = m_position; if (pos.isNull()) return; - + // Update the position otherwise it may become invalid after the selection is deleted. - Node *positionNode = m_position.node(); - int positionOffset = m_position.deprecatedEditingOffset(); - Position selectionEnd = selection.end(); - int selectionEndOffset = selectionEnd.deprecatedEditingOffset(); - if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) { - positionOffset -= selectionEndOffset; - Position selectionStart = selection.start(); - if (selectionStart.node() == positionNode) { - positionOffset += selectionStart.deprecatedEditingOffset(); - } - pos = Position(positionNode, positionOffset); + Position selectionEnd = endingSelection().end(); + if (pos.anchorType() == Position::PositionIsOffsetInAnchor && selectionEnd.anchorType() == Position::PositionIsOffsetInAnchor + && selectionEnd.containerNode() == pos.containerNode() && selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) { + pos.moveToOffset(pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode()); + + Position selectionStart = endingSelection().start(); + if (selectionStart.anchorType() == Position::PositionIsOffsetInAnchor && selectionStart.containerNode() == pos.containerNode()) + pos.moveToOffset(pos.offsetInContainerNode() + selectionStart.offsetInContainerNode()); } deleteSelection(m_smartDelete); @@ -70,11 +66,11 @@ void MoveSelectionCommand::doApply() pos = endingSelection().start(); setEndingSelection(VisibleSelection(pos, endingSelection().affinity())); - if (!positionNode->inDocument()) { + if (!pos.anchorNode()->inDocument()) { // Document was modified out from under us. return; } - applyCommandToComposite(ReplaceSelectionCommand::create(positionNode->document(), m_fragment, true, m_smartInsert)); + applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, true, m_smartInsert)); } EditAction MoveSelectionCommand::editingAction() const |