Commit 021b078a authored by oshima@chromium.org's avatar oshima@chromium.org

Don't merge replace edit if previous edit is delete edit.

Enable UndoRedo_CutCopyPasteTest

BUG=103988,97845
TEST=added new UndoRedo_BackspaceThenSetText, enabled CutCopyPasteTest


Review URL: http://codereview.chromium.org/8823007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113525 0039d316-1c4b-4281-b951-d872f2087c98
parent 91ebba30
...@@ -58,8 +58,12 @@ class Edit { ...@@ -58,8 +58,12 @@ class Edit {
// successful, or false otherwise. Merged edit will be deleted after // successful, or false otherwise. Merged edit will be deleted after
// redo and should not be reused. // redo and should not be reused.
bool Merge(const Edit* edit) { bool Merge(const Edit* edit) {
if (edit->merge_with_previous()) { // Don't merge if previous edit is DELETE. This happens when a
MergeSet(edit); // user deletes characters then hits return. In this case, the
// delete should be treated as separate edit that can be undone
// and should not be merged with the replace edit.
if (type_ != DELETE_EDIT && edit->merge_with_previous()) {
MergeReplace(edit);
return true; return true;
} }
return mergeable() && edit->mergeable() && DoMerge(edit); return mergeable() && edit->mergeable() && DoMerge(edit);
...@@ -113,10 +117,10 @@ class Edit { ...@@ -113,10 +117,10 @@ class Edit {
// Returns the end index of the |new_text_|. // Returns the end index of the |new_text_|.
size_t new_text_end() const { return new_text_start_ + new_text_.length(); } size_t new_text_end() const { return new_text_start_ + new_text_.length(); }
// Merge the Set edit into the current edit. This is a special case to // Merge the replace edit into the current edit. This is a special case to
// handle an omnibox setting autocomplete string after new character is // handle an omnibox setting autocomplete string after new character is
// typed in. // typed in.
void MergeSet(const Edit* edit) { void MergeReplace(const Edit* edit) {
CHECK_EQ(REPLACE_EDIT, edit->type_); CHECK_EQ(REPLACE_EDIT, edit->type_);
CHECK_EQ(0U, edit->old_text_start_); CHECK_EQ(0U, edit->old_text_start_);
CHECK_EQ(0U, edit->new_text_start_); CHECK_EQ(0U, edit->new_text_start_);
......
...@@ -1179,14 +1179,31 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { ...@@ -1179,14 +1179,31 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) {
EXPECT_FALSE(model.Redo()); EXPECT_FALSE(model.Redo());
} }
#if defined(USE_AURA) && defined(OS_LINUX) TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) {
// This can be re-enabled when aura on linux has clipboard support. // This is to test the undo/redo behavior of omnibox.
// http://crbug.com/97845 TextfieldViewsModel model(NULL);
#define MAYBE_UndoRedo_CutCopyPasteTest DISABLED_UndoRedo_CutCopyPasteTest model.InsertChar('w');
#else EXPECT_STR_EQ("w", model.GetText());
#define MAYBE_UndoRedo_CutCopyPasteTest UndoRedo_CutCopyPasteTest EXPECT_EQ(1U, model.GetCursorPosition());
#endif model.SetText(ASCIIToUTF16("www.google.com"));
TEST_F(TextfieldViewsModelTest, MAYBE_UndoRedo_CutCopyPasteTest) { EXPECT_EQ(1U, model.GetCursorPosition());
EXPECT_STR_EQ("www.google.com", model.GetText());
model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text.
model.MoveCursorRight(gfx::LINE_BREAK, false);
EXPECT_EQ(14U, model.GetCursorPosition());
EXPECT_TRUE(model.Backspace());
EXPECT_TRUE(model.Backspace());
EXPECT_STR_EQ("www.google.c", model.GetText());
// Autocomplete sets the text
model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c"));
EXPECT_STR_EQ("www.google.com/search=www.google.c", model.GetText());
EXPECT_TRUE(model.Undo());
EXPECT_STR_EQ("www.google.c", model.GetText());
EXPECT_TRUE(model.Undo());
EXPECT_STR_EQ("www.google.com", model.GetText());
}
TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
TextfieldViewsModel model(NULL); TextfieldViewsModel model(NULL);
model.SetText(ASCIIToUTF16("ABCDE")); model.SetText(ASCIIToUTF16("ABCDE"));
EXPECT_FALSE(model.Redo()); // nothing to redo EXPECT_FALSE(model.Redo()); // nothing to redo
......
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