Skip to content

Commit

Permalink
Merge pull request #1 from letatas/backport/facelessuser#26
Browse files Browse the repository at this point in the history
Backporting issue facelessuser#26 to ST2
  • Loading branch information
letatas committed Mar 26, 2015
2 parents 8c0dde1 + 1ae73e9 commit 653a1ef
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions rr_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def __init__(self, view, edit, find_only, full_file, selection_only, max_sweeps,
settings = sublime.load_settings('reg_replace.sublime-settings')
self.extend = bool(settings.get("extended_back_references", False))

def view_replace(self, region, replacement):
tabs_to_spaces = self.view.settings().get('translate_tabs_to_spaces', False)
if tabs_to_spaces:
self.view.settings().set('translate_tabs_to_spaces', False)
self.view.replace(self.edit, region, replacement)
if tabs_to_spaces:
self.view.settings().set('translate_tabs_to_spaces', True)

def close(self):
"""
Clean up for the object. Mainly clean up the tracked loaded plugins.
Expand Down Expand Up @@ -147,7 +155,7 @@ def greedy_replace(self, find, replace, regions, scope_filter):
self.target_regions.append(region)
else:
# Apply replace
self.view.replace(self.edit, region, replace[count])
self.view_replace(region, replace[count])
count -= 1
return replaced

Expand Down Expand Up @@ -207,7 +215,7 @@ def non_greedy_replace(self, find, replace, regions, scope_filter):
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, replace[selection_index])
self.view_replace(selected_region, replace[selection_index])
return replaced

def expand(self, m, replace):
Expand Down Expand Up @@ -381,7 +389,7 @@ def greedy_scope_literal_replace(self, regions, find, replace, greedy_replace):
if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, extraction)
self.view_replace(region, extraction)
return total_replaced

def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replace):
Expand Down Expand Up @@ -456,7 +464,7 @@ def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replac
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, selected_extraction)
self.view_replace(selected_region, selected_extraction)
return total_replaced

def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi):
Expand All @@ -475,7 +483,7 @@ def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi)
if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, extraction)
self.view_replace(region, extraction)
except Exception as err:
print(str(traceback.format_exc()))
sublime.error_message('REGEX ERROR: %s' % str(err))
Expand Down Expand Up @@ -547,7 +555,7 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, selected_extraction)
self.view_replace(selected_region, selected_extraction)
return total_replaced

def select_scope_regions(self, regions, greedy_scope):
Expand Down

0 comments on commit 653a1ef

Please sign in to comment.