| 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 d5bec8b33248d549600280d137186bbcf8557850..5fbe713e00743f0a586951537a0dff9c0026b542 100644
|
| --- a/ui/views/controls/textfield/textfield_model.cc
|
| +++ b/ui/views/controls/textfield/textfield_model.cc
|
| @@ -35,16 +35,19 @@ class Edit {
|
|
|
| // Revert the change made by this edit in |model|.
|
| void Undo(TextfieldModel* model) {
|
| +
|
| + size_t selection_end = old_text_start_ + old_text_.length();
|
| + gfx::Range selection_range = delete_backward_ ? gfx::Range(selection_end, old_text_start_) : gfx::Range(old_text_start_, selection_end);
|
| model->ModifyText(new_text_start_, new_text_end(),
|
| old_text_, old_text_start_,
|
| - old_cursor_pos_);
|
| + selection_range);
|
| }
|
|
|
| // Apply the change of this edit to the |model|.
|
| void Redo(TextfieldModel* model) {
|
| model->ModifyText(old_text_start_, old_text_end(),
|
| new_text_, new_text_start_,
|
| - new_cursor_pos_);
|
| + gfx::Range(new_cursor_pos_));
|
| }
|
|
|
| // Try to merge the |edit| into this edit and returns true on success. The
|
| @@ -489,13 +492,6 @@ bool TextfieldModel::Cut() {
|
| if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) {
|
| ui::ScopedClipboardWriter(
|
| ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText());
|
| - // A trick to let undo/redo handle cursor correctly.
|
| - // Undoing CUT moves the cursor to the end of the change rather
|
| - // than beginning, unlike Delete/Backspace.
|
| - // TODO(oshima): Change Delete/Backspace to use DeleteSelection,
|
| - // update DeleteEdit and remove this trick.
|
| - const gfx::Range& selection = render_text_->selection();
|
| - render_text_->SelectRange(gfx::Range(selection.end(), selection.start()));
|
| DeleteSelection();
|
| return true;
|
| }
|
| @@ -768,7 +764,7 @@ void TextfieldModel::ModifyText(size_t delete_from,
|
| size_t delete_to,
|
| const base::string16& new_text,
|
| size_t new_text_insert_at,
|
| - size_t new_cursor_pos) {
|
| + gfx::Range selection_range) {
|
| DCHECK_LE(delete_from, delete_to);
|
| base::string16 old_text = text();
|
| ClearComposition();
|
| @@ -776,8 +772,13 @@ void TextfieldModel::ModifyText(size_t delete_from,
|
| render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from));
|
| if (!new_text.empty())
|
| render_text_->SetText(old_text.insert(new_text_insert_at, new_text));
|
| - render_text_->SetCursorPosition(new_cursor_pos);
|
| - // TODO(oshima): Select text that was just undone, like Mac (but not GTK).
|
| +
|
| + // Both result in different caret affinities for an empty range with non 0
|
| + // position.
|
| + if(selection_range.is_empty())
|
| + render_text_->SetCursorPosition(selection_range.start());
|
| + else
|
| + render_text_->SelectRange(selection_range);
|
| }
|
|
|
| } // namespace views
|
|
|