MCPcopy Index your code
hub / github.com/python/cpython / InsertCommand

Class InsertCommand

Lib/idlelib/undo.py:207–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205
206
207class InsertCommand(Command):
208 # Undoable insert command
209
210 def __init__(self, index1, chars, tags=None):
211 Command.__init__(self, index1, None, chars, tags)
212
213 def do(self, text):
214 self.marks_before = self.save_marks(text)
215 self.index1 = text.index(self.index1)
216 if text.compare(self.index1, ">", "end-1c"):
217 # Insert before the final newline
218 self.index1 = text.index("end-1c")
219 text.insert(self.index1, self.chars, self.tags)
220 self.index2 = text.index("%s+%dc" % (self.index1, len(self.chars)))
221 self.marks_after = self.save_marks(text)
222 ##sys.__stderr__.write("do: %s\n" % self)
223
224 def redo(self, text):
225 text.mark_set('insert', self.index1)
226 text.insert(self.index1, self.chars, self.tags)
227 self.set_marks(text, self.marks_after)
228 text.see('insert')
229 ##sys.__stderr__.write("redo: %s\n" % self)
230
231 def undo(self, text):
232 text.mark_set('insert', self.index1)
233 text.delete(self.index1, self.index2)
234 self.set_marks(text, self.marks_before)
235 text.see('insert')
236 ##sys.__stderr__.write("undo: %s\n" % self)
237
238 def merge(self, cmd):
239 if self.__class__ is not cmd.__class__:
240 return False
241 if self.index2 != cmd.index1:
242 return False
243 if self.tags != cmd.tags:
244 return False
245 if len(cmd.chars) != 1:
246 return False
247 if self.chars and \
248 self.classify(self.chars[-1]) != self.classify(cmd.chars):
249 return False
250 self.index2 = cmd.index2
251 self.chars = self.chars + cmd.chars
252 return True
253
254 alphanumeric = string.ascii_letters + string.digits + "_"
255
256 def classify(self, c):
257 if c in self.alphanumeric:
258 return "alphanumeric"
259 if c == "\n":
260 return "newline"
261 return "punctuation"
262
263
264class DeleteCommand(Command):

Callers 1

insertMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…