| 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 7c6d5917f209fdcfbc0b5bb6c1c71ad1622e0044..a43a552fe0470d898d54c8c0299de37e395ca658 100644
|
| --- a/ui/views/controls/textfield/textfield_model.cc
|
| +++ b/ui/views/controls/textfield/textfield_model.cc
|
| @@ -15,6 +15,7 @@
|
| #include "ui/base/clipboard/scoped_clipboard_writer.h"
|
| #include "ui/gfx/range/range.h"
|
| #include "ui/gfx/utf16_indexing.h"
|
| +#include "ui/views/views_delegate.h"
|
|
|
| namespace views {
|
|
|
| @@ -263,6 +264,17 @@ gfx::Range GetFirstEmphasizedRange(const ui::CompositionText& composition) {
|
| return gfx::Range::InvalidRange();
|
| }
|
|
|
| +// Helper functions to get/set the kill buffer.
|
| +const base::string16& GetKillBuffer() {
|
| + DCHECK(ViewsDelegate::GetInstance());
|
| + return ViewsDelegate::GetInstance()->kill_buffer();
|
| +}
|
| +
|
| +void SetKillBuffer(const base::string16& kill_buffer) {
|
| + if (ViewsDelegate::GetInstance())
|
| + ViewsDelegate::GetInstance()->set_kill_buffer(kill_buffer);
|
| +}
|
| +
|
| } // namespace
|
|
|
| using internal::Edit;
|
| @@ -325,13 +337,15 @@ void TextfieldModel::Append(const base::string16& new_text) {
|
| ClearSelection();
|
| }
|
|
|
| -bool TextfieldModel::Delete() {
|
| +bool TextfieldModel::Delete(bool add_to_kill_buffer) {
|
| if (HasCompositionText()) {
|
| // No undo/redo for composition text.
|
| CancelCompositionText();
|
| return true;
|
| }
|
| if (HasSelection()) {
|
| + if (add_to_kill_buffer)
|
| + SetKillBuffer(GetSelectedText());
|
| DeleteSelection();
|
| return true;
|
| }
|
| @@ -339,20 +353,24 @@ bool TextfieldModel::Delete() {
|
| size_t cursor_position = GetCursorPosition();
|
| size_t next_grapheme_index = render_text_->IndexOfAdjacentGrapheme(
|
| cursor_position, gfx::CURSOR_FORWARD);
|
| - ExecuteAndRecordDelete(gfx::Range(cursor_position, next_grapheme_index),
|
| - true);
|
| + gfx::Range range_to_delete(cursor_position, next_grapheme_index);
|
| + if (add_to_kill_buffer)
|
| + SetKillBuffer(GetTextFromRange(range_to_delete));
|
| + ExecuteAndRecordDelete(range_to_delete, true);
|
| return true;
|
| }
|
| return false;
|
| }
|
|
|
| -bool TextfieldModel::Backspace() {
|
| +bool TextfieldModel::Backspace(bool add_to_kill_buffer) {
|
| if (HasCompositionText()) {
|
| // No undo/redo for composition text.
|
| CancelCompositionText();
|
| return true;
|
| }
|
| if (HasSelection()) {
|
| + if (add_to_kill_buffer)
|
| + SetKillBuffer(GetSelectedText());
|
| DeleteSelection();
|
| return true;
|
| }
|
| @@ -360,7 +378,10 @@ bool TextfieldModel::Backspace() {
|
| if (cursor_position > 0) {
|
| // Delete one code point, which may be two UTF-16 words.
|
| size_t previous_char = gfx::UTF16OffsetToIndex(text(), cursor_position, -1);
|
| - ExecuteAndRecordDelete(gfx::Range(cursor_position, previous_char), true);
|
| + gfx::Range range_to_delete(cursor_position, previous_char);
|
| + if (add_to_kill_buffer)
|
| + SetKillBuffer(GetTextFromRange(range_to_delete));
|
| + ExecuteAndRecordDelete(range_to_delete, true);
|
| return true;
|
| }
|
| return false;
|
| @@ -557,6 +578,18 @@ bool TextfieldModel::Transpose() {
|
| return true;
|
| }
|
|
|
| +bool TextfieldModel::Yank() {
|
| + if (!ViewsDelegate::GetInstance())
|
| + return false;
|
| +
|
| + const base::string16& kill_buffer = GetKillBuffer();
|
| + if (!kill_buffer.empty() || HasSelection()) {
|
| + InsertTextInternal(kill_buffer, false);
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| bool TextfieldModel::HasSelection() const {
|
| return !render_text_->selection().is_empty();
|
| }
|
|
|