Replace search pattern in text with replacement value.
(self)
| 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. |
no test coverage detected