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

Unified Diff: views/controls/textfield/textfield_views_model.cc

Issue 5972008: views: Improve cursor movements on word boundaries. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a test with leading whitespace. Created 9 years, 12 months 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 | « views/controls/textfield/native_textfield_views_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/textfield/textfield_views_model.cc
diff --git a/views/controls/textfield/textfield_views_model.cc b/views/controls/textfield/textfield_views_model.cc
index 0b88c8a0781e197fc4266d5561422ac5c6ee219a..0f5b23bdb4b2430c7670909df68a71d31b41b583 100644
--- a/views/controls/textfield/textfield_views_model.cc
+++ b/views/controls/textfield/textfield_views_model.cc
@@ -132,27 +132,28 @@ void TextfieldViewsModel::MoveCursorToPreviousWord(bool select) {
DCHECK(success);
if (!success)
return;
- int prev = 0;
+ int last = 0;
while (iter.Advance()) {
if (iter.IsWord()) {
size_t begin = iter.pos() - iter.GetString().length();
if (begin == cursor_pos_) {
// The cursor is at the beginning of a word.
// Move to previous word.
- cursor_pos_ = prev;
+ break;
} else if(iter.pos() >= cursor_pos_) {
// The cursor is in the middle or at the end of a word.
// Move to the top of current word.
- cursor_pos_ = begin;
+ last = begin;
+ break;
} else {
- prev = iter.pos() - iter.GetString().length();
- continue;
+ last = iter.pos() - iter.GetString().length();
}
- if (!select)
- ClearSelection();
- break;
}
}
+
+ cursor_pos_ = last;
+ if (!select)
+ ClearSelection();
}
void TextfieldViewsModel::MoveCursorToNextWord(bool select) {
@@ -161,14 +162,16 @@ void TextfieldViewsModel::MoveCursorToNextWord(bool select) {
DCHECK(success);
if (!success)
return;
+ size_t pos = 0;
while (iter.Advance()) {
- if (iter.IsWord() && iter.pos() > cursor_pos_) {
- cursor_pos_ = iter.pos();
- if (!select)
- ClearSelection();
+ pos = iter.pos();
+ if (iter.IsWord() && pos > cursor_pos_) {
break;
}
}
+ cursor_pos_ = pos;
+ if (!select)
+ ClearSelection();
}
void TextfieldViewsModel::MoveCursorToStart(bool select) {
« no previous file with comments | « views/controls/textfield/native_textfield_views_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698