WebCore:
Reviewed by Darin Adler.
Correcting the fix for:
<rdar://problem/5544856>
REGRESSION: After typing 2-byte text, undo only undoes one keystroke at a time
Made removal of the previous composition part of the current Undo step in the
case where the new composition is the empty string, too.
* editing/Editor.cpp:
(WebCore::Editor::confirmComposition): Call the new TypingCommand::deleteSelection,
which either has the currently open typing command delete the current selection, or
opens a new typing command (of type DeleteSelection) if one is not already open.
(WebCore::Editor::setComposition): Ditto.
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::deleteSelection): Added.
(WebCore::TypingCommand::doApply): Handle DeleteSelection.
(WebCore::TypingCommand::deleteKeyPressed): Clarified which deleteSelection
is called.
(WebCore::TypingCommand::forwardDeleteKeyPressed): Ditto.
(WebCore::TypingCommand::preservesTypingStyle): Handle DeleteSelection.
* editing/TypingCommand.h:
LayoutTests:
Reviewed by Darin.
<rdar://problem/5544856>
REGRESSION: After typing 2-byte text, undo only undoes one keystroke at a time
* platform/mac/editing/input/text-input-controller-expected.txt: The delete
we were using previously to remove the old composition makes fewer calls to
the editing delegate.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27009 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/editing/TypingCommand.cpp b/WebCore/editing/TypingCommand.cpp
index 1416589..dff9eb3 100644
--- a/WebCore/editing/TypingCommand.cpp
+++ b/WebCore/editing/TypingCommand.cpp
@@ -56,6 +56,27 @@
{
}
+void TypingCommand::deleteSelection(Document* document, bool smartDelete)
+{
+ ASSERT(document);
+
+ Frame* frame = document->frame();
+ ASSERT(frame);
+
+ if (!frame->selectionController()->isRange())
+ return;
+
+ EditCommand* lastEditCommand = frame->editor()->lastEditCommand();
+ if (isOpenForMoreTypingCommand(lastEditCommand)) {
+ static_cast<TypingCommand*>(lastEditCommand)->deleteSelection(smartDelete);
+ return;
+ }
+
+ RefPtr<TypingCommand> typingCommand = new TypingCommand(document, DeleteSelection, "", false);
+ typingCommand->setSmartDelete(smartDelete);
+ typingCommand->apply();
+}
+
void TypingCommand::deleteKeyPressed(Document *document, bool smartDelete, TextGranularity granularity)
{
ASSERT(document);
@@ -226,6 +247,9 @@
m_openedByBackwardDelete = true;
switch (m_commandType) {
+ case DeleteSelection:
+ deleteSelection(m_smartDelete);
+ return;
case DeleteKey:
deleteKeyPressed(m_granularity);
return;
@@ -402,7 +426,7 @@
// more text than you insert. In that case all of the text that was around originally should be selected.
if (m_openedByBackwardDelete)
setStartingSelection(selectionAfterUndo);
- deleteSelection(selectionToDelete, m_smartDelete);
+ CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete);
setSmartDelete(false);
typingAddedToOpenCommand();
}
@@ -472,15 +496,21 @@
if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(selectionToDelete)) {
// make undo select what was deleted
setStartingSelection(selectionAfterUndo);
- deleteSelection(selectionToDelete, m_smartDelete);
+ CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete);
setSmartDelete(false);
typingAddedToOpenCommand();
}
}
+void TypingCommand::deleteSelection(bool smartDelete)
+{
+ CompositeEditCommand::deleteSelection(smartDelete);
+}
+
bool TypingCommand::preservesTypingStyle() const
{
switch (m_commandType) {
+ case DeleteSelection:
case DeleteKey:
case ForwardDeleteKey:
case InsertParagraphSeparator: