Skip to content

Commit 2ce9c0f

Browse files
committed
Handle sublime removing regions while applying edits (sublimelsp#224)
1 parent 0133bae commit 2ce9c0f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plugin/core/edit.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ def run(self, edit, changes=None, show_status=True):
4848
self.view.add_regions('lsp_edit', regions, "source.python")
4949

5050
index = 0
51-
# use regions from view as they are correctly updated after edits.
51+
last_region_count = len(regions)
5252
for newText in replacements:
53-
region = self.view.get_regions('lsp_edit')[index]
53+
# refresh updated regions after each edit.
54+
updated_regions = self.view.get_regions('lsp_edit')
55+
region = updated_regions[index] #
5456
self.apply_change(region, newText, edit)
55-
index += 1
57+
if len(self.view.get_regions('lsp_edit')) == last_region_count:
58+
index += 1 # no regions lost, move to next region.
59+
else:
60+
# current region was removed, don't advance index.
61+
last_region_count = len(self.view.get_regions('lsp_edit'))
5662

5763
self.view.erase_regions('lsp_edit')
5864
if show_status:

0 commit comments

Comments
 (0)