Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update the phantom while typing #62

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugin/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def on_modified_async(self) -> None:
return

vcm = ViewCompletionManager(self.view)
vcm.handle_text_change()
if vcm.handle_text_change():
return

if not self._is_saving and get_session_setting(session, "auto_ask_completions") and not vcm.is_waiting:
plugin.request_get_completions(self.view)
Expand Down
26 changes: 23 additions & 3 deletions plugin/ui/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,31 @@ def handle_selection_change(self) -> None:

self.hide()

def handle_text_change(self) -> None:
def handle_text_change(self) -> bool:
if not (self.is_phantom and self.is_visible):
return
return False

self.hide()
if self.current_completion and len(self.view.sel()) == 1 and self.view.sel()[0].empty():
current_completion = self.current_completion
point = self.view.sel()[0].begin()
region = sublime.Region(current_completion["point"], point)
text = self.view.substr(region)

if current_completion["displayText"].startswith(text):
current_completion["displayText"] = current_completion["displayText"][len(region) :]
self.completion_style_type(
self.view, current_completion, self.completion_index, len(self.completions)
).show()

return True
else:
self.hide()

return False
else:
self.hide()

return False

def handle_close(self) -> None:
if not self.is_phantom:
Expand Down