Home | History | Annotate | Download | only in textfield

Lines Matching refs:edit

20 // Edit holds state information to undo/redo editing changes. Editing operations
22 // Commit() marks an edit as an independent operation that shouldn't be merged.
23 class Edit {
31 virtual ~Edit() {}
33 // Revert the change made by this edit in |model|.
40 // Apply the change of this edit to the |model|.
47 // Try to merge the |edit| into this edit and returns true on success. The
48 // merged edit will be deleted after redo and should not be reused.
49 bool Merge(const Edit* edit) {
50 // Don't merge if previous edit is DELETE. This happens when a
52 // delete should be treated as separate edit that can be undone
53 // and should not be merged with the replace edit.
54 if (type_ != DELETE_EDIT && edit->force_merge()) {
55 MergeReplace(edit);
58 return mergeable() && edit->mergeable() && DoMerge(edit);
61 // Commits the edit and marks as un-mergeable.
69 Edit(Type type,
89 // Each type of edit provides its own specific merge implementation.
90 virtual bool DoMerge(const Edit* edit) = 0;
94 // Can this edit be merged?
97 // Should this edit be forcibly merged with the previous edit?
106 // Merge the replace edit into the current edit. This handles the special case
108 void MergeReplace(const Edit* edit) {
109 CHECK_EQ(REPLACE_EDIT, edit->type_);
110 CHECK_EQ(0U, edit->old_text_start_);
111 CHECK_EQ(0U, edit->new_text_start_);
112 base::string16 old_text = edit->old_text_;
116 // replaced text with |this| edit undone.
118 old_text_start_ = edit->old_text_start_;
121 new_text_ = edit->new_text_;
122 new_text_start_ = edit->new_text_start_;
128 // True if the edit can be marged.
132 // Deleted text by this edit.
145 DISALLOW_COPY_AND_ASSIGN(Edit);
148 class InsertEdit : public Edit {
151 : Edit(INSERT_EDIT,
162 // Edit implementation.
163 virtual bool DoMerge(const Edit* edit) OVERRIDE {
164 if (edit->type() != INSERT_EDIT || new_text_end() != edit->new_text_start_)
166 // If continuous edit, merge it.
169 new_text_ += edit->new_text_;
170 new_cursor_pos_ = edit->new_cursor_pos_;
175 class ReplaceEdit : public Edit {
185 : Edit(REPLACE_EDIT, merge_type,
195 // Edit implementation.
196 virtual bool DoMerge(const Edit* edit) OVERRIDE {
197 if (edit->type() == DELETE_EDIT ||
198 new_text_end() != edit->old_text_start_ ||
199 edit->old_text_start_ != edit->new_text_start_)
201 old_text_ += edit->old_text_;
202 new_text_ += edit->new_text_;
203 new_cursor_pos_ = edit->new_cursor_pos_;
208 class DeleteEdit : public Edit {
214 : Edit(DELETE_EDIT,
225 // Edit implementation.
226 virtual bool DoMerge(const Edit* edit) OVERRIDE {
227 if (edit->type() != DELETE_EDIT)
232 if (!edit->delete_backward_ || old_text_start_ != edit->old_text_end())
234 old_text_start_ = edit->old_text_start_;
235 old_text_ = edit->old_text_ + old_text_;
236 new_cursor_pos_ = edit->new_cursor_pos_;
239 if (edit->delete_backward_ || old_text_start_ != edit->old_text_start_)
241 old_text_ += edit->old_text_;
265 using internal::Edit;
303 // If there is a composition text, don't merge with previous edit.
443 // There is no redo iff the current edit is the last element in the history.
665 // Edit history is recorded in InsertText.
686 Edit* edit = new DeleteEdit(mergeable, old_text, old_text_start, backward);
687 bool delete_edit = AddOrMergeEditHistory(edit);
688 edit->Redo(this);
690 delete edit;
712 Edit* edit = new ReplaceEdit(merge_type,
720 bool delete_edit = AddOrMergeEditHistory(edit);
721 edit->Redo(this);
723 delete edit;
728 Edit* edit = new InsertEdit(mergeable, new_text, GetCursorPosition());
729 bool delete_edit = AddOrMergeEditHistory(edit);
730 edit->Redo(this);
732 delete edit;
735 bool TextfieldModel::AddOrMergeEditHistory(Edit* edit) {
738 if (current_edit_ != edit_history_.end() && (*current_edit_)->Merge(edit)) {
739 // If a current edit exists and has been merged with a new edit, don't add
740 // to the history, and return true to delete |edit| after redo.
743 edit_history_.push_back(edit);
745 // If there is no redoable edit, this is the 1st edit because RedoHistory