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

Side by Side Diff: ui/gfx/render_text.cc

Issue 13972015: Select last word when double clicked after the last character (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 2 Created 7 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 468
469 size_t cursor_pos = cursor_position(); 469 size_t cursor_pos = cursor_position();
470 470
471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
472 bool success = iter.Init(); 472 bool success = iter.Init();
473 DCHECK(success); 473 DCHECK(success);
474 if (!success) 474 if (!success)
475 return; 475 return;
476 476
477 size_t selection_start = cursor_pos; 477 size_t selection_start = cursor_pos;
478 if (selection_start == text().length() && selection_start != 0)
479 --selection_start;
480
478 for (; selection_start != 0; --selection_start) { 481 for (; selection_start != 0; --selection_start) {
479 if (iter.IsStartOfWord(selection_start) || 482 if (iter.IsStartOfWord(selection_start) ||
480 iter.IsEndOfWord(selection_start)) 483 iter.IsEndOfWord(selection_start))
481 break; 484 break;
482 } 485 }
483 486
484 if (selection_start == cursor_pos) 487 if (selection_start == cursor_pos)
485 ++cursor_pos; 488 ++cursor_pos;
486 489
487 for (; cursor_pos < text().length(); ++cursor_pos) 490 for (; cursor_pos < text().length(); ++cursor_pos)
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 void RenderText::DrawCursor(Canvas* canvas) { 969 void RenderText::DrawCursor(Canvas* canvas) {
967 // Paint cursor. Replace cursor is drawn as rectangle for now. 970 // Paint cursor. Replace cursor is drawn as rectangle for now.
968 // TODO(msw): Draw a better cursor with a better indication of association. 971 // TODO(msw): Draw a better cursor with a better indication of association.
969 if (cursor_enabled() && cursor_visible() && focused()) { 972 if (cursor_enabled() && cursor_visible() && focused()) {
970 canvas->FillRect(GetUpdatedCursorBounds(), 973 canvas->FillRect(GetUpdatedCursorBounds(),
971 insert_mode_ ? cursor_color_ : selection_background_unfocused_color_); 974 insert_mode_ ? cursor_color_ : selection_background_unfocused_color_);
972 } 975 }
973 } 976 }
974 977
975 } // namespace gfx 978 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698