summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_views.cc28
-rw-r--r--views/controls/textfield/native_textfield_views.h1
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc32
3 files changed, 61 insertions, 0 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 677ada5..2a42c5a 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -464,10 +464,38 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
cursor_changed = true;
break;
case app::VKEY_BACK:
+ if (!model_->HasSelection()) {
+ if (selection && control) {
+ // If both shift and control are pressed, then erase upto the
+ // beginning of the buffer in ChromeOS. In windows, do nothing.
+#if defined(OS_WIN)
+ break;
+#else
+ model_->MoveCursorToStart(true);
+#endif
+ } else if (control) {
+ // If only control is pressed, then erase the previous word.
+ model_->MoveCursorToPreviousWord(true);
+ }
+ }
text_changed = model_->Backspace();
cursor_changed = true;
break;
case app::VKEY_DELETE:
+ if (!model_->HasSelection()) {
+ if (selection && control) {
+ // If both shift and control are pressed, then erase upto the
+ // end of the buffer in ChromeOS. In windows, do nothing.
+#if defined(OS_WIN)
+ break;
+#else
+ model_->MoveCursorToEnd(true);
+#endif
+ } else if (control) {
+ // If only control is pressed, then erase the next word.
+ model_->MoveCursorToNextWord(true);
+ }
+ }
text_changed = model_->Delete();
break;
case app::VKEY_INSERT:
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index 3c023ac..f87c42a 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -33,6 +33,7 @@ class TextfieldViewsModel;
// * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in
// chromeos, so we may not need them)
// * Double click to select word, and triple click to select all.
+// * Undo/Redo
class NativeTextfieldViews : public views::View,
public NativeTextfieldWrapper {
public:
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index efa7eb1..9fc883c 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -250,6 +250,38 @@ TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) {
textfield_->SelectAll();
SendKeyEventToTextfieldViews(app::VKEY_K);
EXPECT_STR_EQ("k", textfield_->text());
+
+ // Delete the previous word from cursor.
+ textfield_->SetText(ASCIIToUTF16("one two three four"));
+ SendKeyEventToTextfieldViews(app::VKEY_END);
+ SendKeyEventToTextfieldViews(app::VKEY_BACK, false, true, false);
+ EXPECT_STR_EQ("one two three ", textfield_->text());
+
+ // Delete upto the beginning of the buffer from cursor in chromeos, do nothing
+ // in windows.
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true, false);
+ SendKeyEventToTextfieldViews(app::VKEY_BACK, true, true, false);
+#if defined(OS_WIN)
+ EXPECT_STR_EQ("one two three ", textfield_->text());
+#else
+ EXPECT_STR_EQ("three ", textfield_->text());
+#endif
+
+ // Delete the next word from cursor.
+ textfield_->SetText(ASCIIToUTF16("one two three four"));
+ SendKeyEventToTextfieldViews(app::VKEY_HOME);
+ SendKeyEventToTextfieldViews(app::VKEY_DELETE, false, true, false);
+ EXPECT_STR_EQ(" two three four", textfield_->text());
+
+ // Delete upto the end of the buffer from cursor in chromeos, do nothing
+ // in windows.
+ SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true, false);
+ SendKeyEventToTextfieldViews(app::VKEY_DELETE, true, true, false);
+#if defined(OS_WIN)
+ EXPECT_STR_EQ(" two three four", textfield_->text());
+#else
+ EXPECT_STR_EQ(" two", textfield_->text());
+#endif
}
TEST_F(NativeTextfieldViewsTest, PasswordTest) {