def replace_confirming(self, edit, pattern, compiled_rx, replacement,
replace_count, target_region):
last_row = row_at(self.view, target_region.b - 1)
start = target_region.begin()
while True:
match = self.view.find(pattern, start)
# no match or match out of range -- stop
if (match == R(-1)) or (row_at(self.view, match.a) > last_row):
self.view.show(first_sel(self.view).begin())
return
size_before = self.view.size()
with adding_regions(self.view, 's_confirm', [match], 'comment'):
self.view.show(match.a, True)
if sublime.ok_cancel_dialog("Confirm replacement?"):
text = self.view.substr(match)
substituted = re.sub(compiled_rx, replacement, text, count=replace_count)
self.view.replace(edit, match, substituted)
start = match.b + (self.view.size() - size_before)
评论列表
文章目录