Skip to content

Commit 37068be

Browse files
randy3ktomv564
authored andcommitted
fix: inserted space get undone
inserted spaces get undone as mentioned at sublimelsp#180 (comment) this PR checks actively if the last text command is insert_best_completion
1 parent 726739b commit 37068be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

plugin/completion.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ def handle_resolve_response(self, response, view):
109109
exception_log("Error inserting snippet: " + insertText, err)
110110

111111

112+
last_text_command = None
113+
114+
115+
class CompletionHelper(sublime_plugin.EventListener):
116+
def on_text_command(self, view, command_name, args):
117+
global last_text_command
118+
last_text_command = command_name
119+
120+
112121
class CompletionHandler(sublime_plugin.ViewEventListener):
113122
def __init__(self, view):
114123
self.view = view
@@ -252,7 +261,10 @@ def handle_response(self, response: dict):
252261
# if insert_best_completion was just ran, undo it before presenting new completions.
253262
prev_char = self.view.substr(self.view.sel()[0].begin() - 1)
254263
if prev_char.isspace():
255-
self.view.run_command("undo")
264+
if last_text_command == "insert_best_completion":
265+
self.view.run_command("undo")
266+
else:
267+
return
256268

257269
self.state = CompletionState.APPLYING
258270
self.view.run_command("hide_auto_complete")

0 commit comments

Comments
 (0)