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

Unified Diff: ui/views/controls/textfield/textfield.cc

Issue 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 19e5c2ca689acbd6ab7cc7c045d7ef6bdd536c3e..c2d134d076a3127d4027144df4c808a873c33dde 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1488,6 +1488,8 @@ bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
return editable && !result.empty();
case ui::TextEditCommand::SELECT_ALL:
return !text().empty();
+ case ui::TextEditCommand::YANK:
+ return editable;
case ui::TextEditCommand::MOVE_DOWN:
case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_PAGE_DOWN:
@@ -1538,21 +1540,24 @@ base::string16 Textfield::GetSelectionClipboardText() const {
void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
DestroyTouchSelection();
+ bool add_to_kill_buffer = false;
+
// Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
// modifications of the command should happen here.
- if (HasSelection()) {
- switch (command) {
- case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
- case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
- case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
- case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
- case ui::TextEditCommand::DELETE_WORD_BACKWARD:
- case ui::TextEditCommand::DELETE_WORD_FORWARD:
+ switch (command) {
+ case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
+ case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
+ case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
+ case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
+ add_to_kill_buffer = true;
karandeepb 2016/07/01 05:49:16 Interestingly Command+X(Cut) also adds text to the
+ // Fall through.
+ case ui::TextEditCommand::DELETE_WORD_BACKWARD:
+ case ui::TextEditCommand::DELETE_WORD_FORWARD:
+ if (HasSelection())
command = ui::TextEditCommand::DELETE_FORWARD;
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
}
// We only execute the commands enabled in Textfield::IsTextEditCommandEnabled
@@ -1570,28 +1575,28 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
OnBeforeUserAction();
switch (command) {
case ui::TextEditCommand::DELETE_BACKWARD:
- text_changed = cursor_changed = model_->Backspace();
+ text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_FORWARD:
- text_changed = cursor_changed = model_->Delete();
+ text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
model_->MoveCursor(gfx::LINE_BREAK, begin, true);
- text_changed = cursor_changed = model_->Backspace();
+ text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
model_->MoveCursor(gfx::LINE_BREAK, end, true);
- text_changed = cursor_changed = model_->Delete();
+ text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_WORD_BACKWARD:
model_->MoveCursor(gfx::WORD_BREAK, begin, true);
- text_changed = cursor_changed = model_->Backspace();
+ text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_WORD_FORWARD:
model_->MoveCursor(gfx::WORD_BREAK, end, true);
- text_changed = cursor_changed = model_->Delete();
+ text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break;
case ui::TextEditCommand::MOVE_BACKWARD:
model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false);
@@ -1681,6 +1686,9 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
case ui::TextEditCommand::SELECT_ALL:
SelectAll(false);
break;
+ case ui::TextEditCommand::YANK:
+ text_changed = cursor_changed = model_->Yank();
+ break;
case ui::TextEditCommand::MOVE_DOWN:
case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_PAGE_DOWN:

Powered by Google App Engine
This is Rietveld 408576698