Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index fe4c59cee9b3239dd18b982628203b55a885b9f6..ee2b498b5e4cd6969a1ca64100660d2c1edfdd75 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -414,8 +414,15 @@ void RenderText::SetText(const base::string16& text) { |
| // Adjust ranged styles and colors to accommodate a new text length. |
| const size_t text_length = text_.length(); |
| colors_.SetMax(text_length); |
| - for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
| - styles_[style].SetMax(text_length); |
| + for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) { |
| + BreakList<bool>& break_list = styles_[style]; |
| + break_list.SetMax(text_length); |
| + // Clear style ranges as they might break new text graphemes. |
|
msw
2014/09/08 19:29:34
nit: Merge this comment with the one on line 414.
Tomasz Moniuszko
2014/09/09 09:59:15
Done.
|
| + // Apply first style to the whole text instead. |
|
msw
2014/09/08 19:29:34
nit: "Apply the first".
Tomasz Moniuszko
2014/09/09 09:59:15
Done.
|
| + if (break_list.breaks().size() > 1) { |
| + break_list.SetValue(break_list.breaks().begin()->second); |
|
msw
2014/09/08 19:29:34
Do this unconditionally, before calling SetMax.
Tomasz Moniuszko
2014/09/09 09:59:15
Done.
|
| + } |
| + } |
| cached_bounds_and_offset_valid_ = false; |
| // Reset selection model. SetText should always followed by SetSelectionModel |
| @@ -651,7 +658,12 @@ void RenderText::SetStyle(TextStyle style, bool value) { |
| } |
| void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) { |
| - styles_[style].ApplyValue(value, range); |
| + // Do not change styles mid-grapheme to avoid breaking ligatures. |
| + const size_t start = IsValidCursorIndex(range.start()) ? range.start() : |
| + IndexOfAdjacentGrapheme(range.start(), CURSOR_BACKWARD); |
| + const size_t end = IsValidCursorIndex(range.end()) ? range.end() : |
| + IndexOfAdjacentGrapheme(range.end(), CURSOR_FORWARD); |
| + styles_[style].ApplyValue(value, Range(start, end)); |
| cached_bounds_and_offset_valid_ = false; |
| ResetLayout(); |