Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: ui/views/controls/textfield/textfield_model.cc

Issue 1492633004: Ensure that text with leading, trailing and interspersed tabs pasted into the textfield (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the TextfieldModelTest.Clipboard test Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield_model.cc
diff --git a/ui/views/controls/textfield/textfield_model.cc b/ui/views/controls/textfield/textfield_model.cc
index d270a20c0a01e8cbcaddd8a6949f208e33dd6e26..6b17c5c69d10a58c9b1ea82a90e8a1850770e917 100644
--- a/ui/views/controls/textfield/textfield_model.cc
+++ b/ui/views/controls/textfield/textfield_model.cc
@@ -8,6 +8,8 @@
#include "base/logging.h"
#include "base/stl_util.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/gfx/range/range.h"
@@ -509,13 +511,18 @@ bool TextfieldModel::Copy() {
}
bool TextfieldModel::Paste() {
- base::string16 result;
+ base::string16 text;
ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
- &result);
- if (result.empty())
+ &text);
+ if (text.empty())
return false;
- InsertTextInternal(result, false);
+ base::string16 actual_text = base::CollapseWhitespace(text, false);
+ // If the clipboard contains all whitespaces then paste a single space.
+ if (actual_text.empty())
+ actual_text = base::ASCIIToUTF16(" ");
+
+ InsertTextInternal(actual_text, false);
return true;
}
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698