def do_replace(self): prog = self.engine.getprog() if not prog: return False text = self.text try: first = pos = text.index("sel.first") last = text.index("sel.last") except TclError: pos = None if not pos: first = last = pos = text.index("insert") line, col = searchengine.get_line_col(pos) chars = text.get("%d.0" % line, "%d.0" % (line + 1)) m = prog.match(chars, col) if not prog: return False new = self._replace_expand(m, self.replvar.get()) if new is None: return False text.mark_set("insert", first) text.undo_block_start() if m.group(): text.delete(first, last) if new: text.insert(first, new) text.undo_block_stop() self.show_hit(first, text.index("insert")) self.ok = 0 return True
def do_replace(self): prog = self.engine.getprog() if not prog: return False text = self.text try: first = pos = text.index("sel.first") last = text.index("sel.last") except TclError: pos = None if not pos: first = last = pos = text.index("insert") line, col = searchengine.get_line_col(pos) chars = text.get("%d.0" % line, "%d.0" % (line+1)) m = prog.match(chars, col) if not prog: return False new = self._replace_expand(m, self.replvar.get()) if new is None: return False text.mark_set("insert", first) text.undo_block_start() if m.group(): text.delete(first, last) if new: text.insert(first, new) text.undo_block_stop() self.show_hit(first, text.index("insert")) self.ok = 0 return True
def test_get_line_col(self): self.assertEqual(se.get_line_col('1.0'), (1, 0)) self.assertEqual(se.get_line_col('1.11'), (1, 11)) self.assertRaises(ValueError, se.get_line_col, ('1.0 lineend')) self.assertRaises(ValueError, se.get_line_col, ('end'))