Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.1, 1.1.1, and 1.1.2

textview: merge with UndoableReplace if possible

Changeset 97a472fe627b

Parent cb0e78351f32

by Yuki KODAMA

Changes to one file · Browse files at 97a472fe627b Showing diff from parent cb0e78351f32 Diff from another changeset...

 
78
79
80
81
 
82
83
84
85
86
 
 
 
87
88
89
 
110
111
112
113
114
 
 
 
 
 
 
115
116
117
 
122
123
124
125
 
126
127
128
129
130
131
 
 
 
132
133
134
 
159
160
161
162
163
164
 
 
 
 
 
 
 
165
166
167
168
 
 
 
169
170
171
 
78
79
80
 
81
82
83
84
85
 
86
87
88
89
90
91
 
112
113
114
 
 
115
116
117
118
119
120
121
122
123
 
128
129
130
 
131
132
133
134
135
136
 
137
138
139
140
141
142
 
167
168
169
 
 
 
170
171
172
173
174
175
176
177
 
 
 
178
179
180
181
182
183
@@ -78,12 +78,14 @@
  """see if we can merge multiple inserts here     will try to merge words or whitespace - can't merge if prev is not UndoableInsert + can't merge if prev is UndoableDelete   can't merge if prev and cur are not mergeable in the first place   can't merge when user set the input bar somewhere else   can't merge across word boundaries"""   WHITESPACE = (' ', '\t') - if not isinstance(prev, UndoableInsert): + if isinstance(prev, UndoableReplace): + prev = prev.second + if isinstance(prev, UndoableDelete):   return False   elif not cur.mergeable or not prev.mergeable:   return False @@ -110,8 +112,12 @@
  if can_be_replaced(prev_action, undo_action):   undo_action = UndoableReplace(prev_action, undo_action)   elif can_be_merged(prev_action, undo_action): - prev_action.length += undo_action.length - prev_action.text += undo_action.text + if isinstance(prev_action, UndoableReplace): + merge_action = prev_action.second + else: + merge_action = prev_action + merge_action.length += undo_action.length + merge_action.text += undo_action.text   undo_action = prev_action   else:   self.undo_stack.append(prev_action) @@ -122,13 +128,15 @@
  """see if we can merge multiple deletions here     will try to merge words or whitespace - can't merge if prev is not UndoableDelete + can't merge if prev is UndoableInsert   can't merge if prev and cur are not mergeable in the first place   can't merge if delete and backspace key were both used   can't merge across word boundaries"""     WHITESPACE = (' ', '\t') - if not isinstance(prev, UndoableDelete): + if isinstance(prev, UndoableReplace): + prev = prev.second + if isinstance(prev, UndoableInsert):   return False   elif not cur.mergeable or not prev.mergeable:   return False @@ -159,13 +167,17 @@
  if can_be_replaced(prev_action, undo_action):   undo_action = UndoableReplace(prev_action, undo_action)   elif can_be_merged(prev_action, undo_action): - if prev_action.start == undo_action.start: # delete key used - prev_action.text += undo_action.text - prev_action.end += (undo_action.end - undo_action.start) + if isinstance(prev_action, UndoableReplace): + merge_action = prev_action.second + else: + merge_action = prev_action + if merge_action.start == undo_action.start: # delete key used + merge_action.text += undo_action.text + merge_action.end += (undo_action.end - undo_action.start)   else: # Backspace used - prev_action.text = '%s%s' % (undo_action.text, - prev_action.text) - prev_action.start = undo_action.start + merge_action.text = '%s%s' % (undo_action.text, + merge_action.text) + merge_action.start = undo_action.start   undo_action = prev_action   else:   self.undo_stack.append(prev_action)