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

Method do_replace

Lib/idlelib/replace.py:198–228  ·  view source on GitHub ↗

Replace search pattern in text with replacement value.

(self)

Source from the content-addressed store, hash-verified

196 return True
197
198 def do_replace(self):
199 "Replace search pattern in text with replacement value."
200 prog = self.engine.getprog()
201 if not prog:
202 return False
203 text = self.text
204 try:
205 first = pos = text.index("sel.first")
206 last = text.index("sel.last")
207 except TclError:
208 pos = None
209 if not pos:
210 first = last = pos = text.index("insert")
211 line, col = searchengine.get_line_col(pos)
212 chars = text.get("%d.0" % line, "%d.0" % (line+1))
213 m = prog.match(chars, col)
214 if not prog:
215 return False
216 new = self._replace_expand(m, self.replvar.get())
217 if new is None:
218 return False
219 text.mark_set("insert", first)
220 text.undo_block_start()
221 if m.group():
222 text.delete(first, last)
223 if new:
224 text.insert(first, new, self.insert_tags)
225 text.undo_block_stop()
226 self.show_hit(first, text.index("insert"))
227 self.ok = False
228 return True
229
230 def show_hit(self, first, last):
231 """Highlight text between first and last indices.

Callers 2

replace_itMethod · 0.95
default_commandMethod · 0.95

Calls 12

_replace_expandMethod · 0.95
show_hitMethod · 0.95
getprogMethod · 0.80
indexMethod · 0.45
getMethod · 0.45
matchMethod · 0.45
mark_setMethod · 0.45
undo_block_startMethod · 0.45
groupMethod · 0.45
deleteMethod · 0.45
insertMethod · 0.45
undo_block_stopMethod · 0.45

Tested by

no test coverage detected