summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorckocagil@chromium.org <ckocagil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 12:43:57 +0000
committerckocagil@chromium.org <ckocagil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 12:43:57 +0000
commit8c496131851133ba744197a899a3ed7d31fa655e (patch)
treef4e28b688e020ed7ce2885a52186d4bbb00b88cc /ui
parent0a561a418c3ef90d703fd5bc7c4b6e766d3bc976 (diff)
downloadchromium_src-8c496131851133ba744197a899a3ed7d31fa655e.zip
chromium_src-8c496131851133ba744197a899a3ed7d31fa655e.tar.gz
chromium_src-8c496131851133ba744197a899a3ed7d31fa655e.tar.bz2
Select last word when double clicked after the last character
When RenderText::SelectWord is called while the cursor is on a boundary, the word to the right is selected. This patch specially handles the case where the cursor is at the rightmost position to select the word to the left. BUG=232023 TEST=See repro steps at http://crbug.com/232023 Review URL: https://chromiumcodereview.appspot.com/13972015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194901 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/render_text.cc3
-rw-r--r--ui/gfx/render_text_unittest.cc20
2 files changed, 23 insertions, 0 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index fc9353f..7d55f0c 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -475,6 +475,9 @@ void RenderText::SelectWord() {
return;
size_t selection_start = cursor_pos;
+ if (selection_start == text().length() && selection_start != 0)
+ --selection_start;
+
for (; selection_start != 0; --selection_start) {
if (iter.IsStartOfWord(selection_start) ||
iter.IsEndOfWord(selection_start))
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index e330fe8..e85cb72 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -1108,6 +1108,26 @@ TEST_F(RenderTextTest, CaretWidth) {
EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1);
}
+// Make sure the last word is selected when the cursor is at text.length().
+TEST_F(RenderTextTest, LastWordSelected) {
+ const std::string kTestURL1 = "http://www.google.com";
+ const std::string kTestURL2 = "http://www.google.com/something/";
+
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+
+ render_text->SetText(ASCIIToUTF16(kTestURL1));
+ render_text->SetCursorPosition(kTestURL1.length());
+ render_text->SelectWord();
+ EXPECT_EQ(ui::Range(kTestURL1.length() - 3, kTestURL1.length()),
+ render_text->selection());
+
+ render_text->SetText(ASCIIToUTF16(kTestURL2));
+ render_text->SetCursorPosition(kTestURL2.length());
+ render_text->SelectWord();
+ EXPECT_EQ(ui::Range(kTestURL2.length() - 1, kTestURL2.length()),
+ render_text->selection());
+}
+
// TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac
// does not implement this yet. http://crbug.com/131618
#if !defined(OS_MACOSX)