Index: WebCore/editing/TypingCommand.cpp |
=================================================================== |
--- WebCore/editing/TypingCommand.cpp (revision 73932) |
+++ WebCore/editing/TypingCommand.cpp (working copy) |
@@ -91,6 +91,7 @@ |
EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); |
if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEditCommand)) { |
+ updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand*>(lastEditCommand), frame); |
static_cast<TypingCommand*>(lastEditCommand)->deleteKeyPressed(granularity, killRing); |
return; |
} |
@@ -110,6 +111,7 @@ |
EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); |
if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEditCommand)) { |
+ updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand*>(lastEditCommand), frame); |
static_cast<TypingCommand*>(lastEditCommand)->forwardDeleteKeyPressed(granularity, killRing); |
return; |
} |
@@ -119,6 +121,18 @@ |
typingCommand->apply(); |
} |
+void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand* typingCommand, Frame* frame) |
+{ |
+ ASSERT(frame); |
+ VisibleSelection currentSelection = frame->selection()->selection(); |
+ if (currentSelection == typingCommand->endingSelection()) |
+ return; |
+ |
+ typingCommand->setStartingSelection(currentSelection); |
+ typingCommand->setEndingSelection(currentSelection); |
+} |
+ |
+ |
void TypingCommand::insertText(Document* document, const String& text, bool selectInsertedText, bool insertedTextIsComposition) |
{ |
ASSERT(document); |
@@ -129,6 +143,7 @@ |
insertText(document, text, frame->selection()->selection(), selectInsertedText, insertedTextIsComposition); |
} |
+// FIXME: We shouldn't need to take selectionForInsertion. It should be identical to SelectionController's current selection. |
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, bool selectInsertedText, bool insertedTextIsComposition) |
{ |
#if REMOVE_MARKERS_UPON_EDITING |
@@ -163,15 +178,11 @@ |
RefPtr<EditCommand> lastEditCommand = frame->editor()->lastEditCommand(); |
if (isOpenForMoreTypingCommand(lastEditCommand.get())) { |
TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand.get()); |
- if (changeSelection) { |
+ if (lastTypingCommand->endingSelection() != selectionForInsertion) { |
lastTypingCommand->setStartingSelection(selectionForInsertion); |
lastTypingCommand->setEndingSelection(selectionForInsertion); |
} |
lastTypingCommand->insertText(newText, selectInsertedText); |
- if (changeSelection) { |
- lastTypingCommand->setEndingSelection(currentSelection); |
- frame->selection()->setSelection(currentSelection); |
- } |
return; |
} |
@@ -371,6 +382,10 @@ |
command = InsertTextCommand::create(document()); |
applyCommandToComposite(command); |
} |
+ if (endingSelection() != command->endingSelection()) { |
+ command->setStartingSelection(endingSelection()); |
+ command->setEndingSelection(endingSelection()); |
+ } |
command->input(text, selectInsertedText); |
typingAddedToOpenCommand(InsertText); |
} |