def OnReplace(self, event): if not self.sc.word: return sp = self.ctrl.sp u = undo.SinglePara(sp, undo.CMD_MISC, self.sc.line) word = util.toInputStr(misc.fromGUI(self.replaceEntry.GetValue())) ls = sp.lines sp.gotoPos(self.sc.line, self.sc.col) ls[self.sc.line].text = util.replace( ls[self.sc.line].text, word, self.sc.col, len(self.sc.word)) sp.rewrapPara(sp.getParaFirstIndexFromLine(self.sc.line)) # rewrapping a paragraph can have moved the cursor, so get the new # location of it, and then advance past the just-changed word self.sc.line = sp.line self.sc.col = sp.column + len(word) sp.clearMark() sp.markChanged() u.setAfter(sp) sp.addUndo(u) self.gotoNext(False)
def OnReplace(self, event=None, autoFind=False): if self.searchLine == -1: return False value = util.toInputStr(misc.fromGUI(self.replaceEntry.GetValue())) ls = self.ctrl.sp.lines sp = self.ctrl.sp u = undo.SinglePara(sp, undo.CMD_MISC, self.searchLine) ls[self.searchLine].text = util.replace(ls[self.searchLine].text, value, self.searchColumn, self.searchWidth) sp.rewrapPara(sp.getParaFirstIndexFromLine(self.searchLine)) self.searchLine = -1 diff = len(value) - self.searchWidth if not self.dirUp: sp.column += self.searchWidth + diff else: sp.column -= 1 if sp.column < 0: sp.line -= 1 if sp.line < 0: sp.line = 0 sp.column = 0 self.searchLine = 0 self.searchColumn = 0 self.searchWidth = 0 else: sp.column = len(ls[sp.line].text) sp.clearMark() sp.markChanged() u.setAfter(sp) sp.addUndo(u) self.OnFind(autoFind=autoFind) return True