-
Notifications
You must be signed in to change notification settings - Fork 96
some changes to make it work like Emacs vertical file completion. #185
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
c6c13fd
988b8a5
9066872
c4dcae7
26a17b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import errno | ||
| import functools | ||
| import os | ||
| import re | ||
| import sublime | ||
|
|
@@ -300,9 +301,11 @@ def clear_input_view_content(self): | |
| def clear_input_view_project_files(self): | ||
| self.get_active_view_settings().erase("anf_input_view_project_files") | ||
|
|
||
| def show_filename_input(self, initial): | ||
| def show_filename_input(self, initial, completion_delay=0): | ||
| caption = self.input_panel_caption() | ||
|
|
||
| self.input_char_count = 0 | ||
| self.completion_delay = completion_delay | ||
| self.input_panel_view = self.window.show_input_panel( | ||
| caption, initial, | ||
| self.on_done, self.__update_filename_input, self.clear | ||
|
|
@@ -320,24 +323,45 @@ def show_filename_input(self, initial): | |
| self.__update_filename_input(initial) | ||
|
|
||
| def __update_filename_input(self, path_in): | ||
| self.input_char_count += 1 | ||
| if not path_in or path_in.endswith("\t") or path_in.endswith("\n"): | ||
| self.__update_filename_input_lazy(path_in, self.input_char_count) | ||
| else: | ||
| sublime.set_timeout( | ||
| functools.partial(self.__update_filename_input_lazy, path_in, self.input_char_count), | ||
| self.completion_delay) | ||
|
|
||
| def __update_filename_input_lazy(self, path_in, count): | ||
| if self.input_char_count != count: | ||
| return | ||
| self.input_char_count = 0 | ||
|
|
||
| new_content = path_in | ||
| if self.settings.get(COMPLETION_TYPE_SETTING) == "windows": | ||
| if "prev_text" in dir(self) and self.prev_text != path_in: | ||
| if self.view is not None: | ||
| self.view.erase_status("AdvancedNewFile2") | ||
|
|
||
| input_view = self.get_input_view() | ||
| if '/~/' in path_in: | ||
| index = path_in.rindex('/~/') | ||
| new_content = path_in[index + 1:] | ||
| if '//' in path_in: | ||
| index = path_in.rindex('//') | ||
| new_content = path_in[index + 1:] | ||
| if input_view and new_content != path_in: | ||
| input_view.run_command("anf_replace", {"content": new_content}) | ||
| return | ||
|
|
||
| if path_in.endswith("\t"): | ||
| creation_path, candidate, completion_list = self.get_input_view_content() | ||
| new_content = self.completion_input(path_in.replace("\n", "").replace("\t", ""), candidate) | ||
| elif path_in.endswith("\n"): | ||
| path_in = path_in.replace("\n", "") | ||
| path_in = path_in.replace("\t", "").replace("\n", "") | ||
| if input_view: | ||
| # print("visible", input_view.is_popup_visible()) | ||
| if input_view.is_popup_visible(): | ||
| input_view.run_command("insert", {"characters": "\t"}) | ||
| else: | ||
| # print("end panel") | ||
| self.on_done(path_in) | ||
| self.window.run_command("hide_panel", {"cancel": True}) | ||
| return | ||
|
|
@@ -510,7 +534,10 @@ def get_cursor_path(self): | |
| path = re.sub('^"|\'', '', re.sub('"|\'$', '', path.strip())) | ||
| break | ||
|
|
||
| return path | ||
| if "/" in path: | ||
| return path | ||
| else: | ||
| return "" | ||
|
Comment on lines
+537
to
+540
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this logic here, but the return value doesn't seem to be used anyway? |
||
|
|
||
| def _expand_default_path(self, path): | ||
| current_file = self.view.file_name() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,10 @@ def __init__(self, window): | |
| def run(self, is_python=False, initial_path=None): | ||
| self.is_python = is_python | ||
| self.run_setup() | ||
| self.show_filename_input(self.generate_initial_path(initial_path)) | ||
| print(self.settings) | ||
| completion_delay = self.settings.get(COMPLETION_DELAY_SETTING, 100) | ||
| print(completion_delay) | ||
|
Comment on lines
+19
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug prints |
||
| self.show_filename_input(self.generate_initial_path(initial_path), completion_delay) | ||
|
|
||
| def get_project_folder(self): | ||
| return sublime.active_window().folders()[0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,16 @@ | |
| # import numpy as np | ||
|
|
||
| def sort_by_fuzzy(query, choices, limit:int = 0): | ||
|
FichteFoll marked this conversation as resolved.
|
||
| if not query or not choices: | ||
| return choices | ||
| choices_ratio = {} | ||
| for choice in choices: | ||
| choices_ratio[choice] = levenshtein_ratio(query, choice) | ||
| if not choices: | ||
| return [] | ||
| if not query: | ||
| result = choices | ||
| else: | ||
| choices_ratio = {} | ||
| for choice in choices: | ||
| choices_ratio[choice] = levenshtein_ratio(query, choice) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better use a dict comprehension now. |
||
| result = [key[0] for key in sorted(choices_ratio.items(), key=itemgetter(1), reverse=True)] | ||
|
|
||
| # print(choices_ratio) | ||
| result = [key[0] for key in sorted(choices_ratio.items(), key=itemgetter(1), reverse=True)] | ||
| if limit > 0 and len(result) > limit: | ||
| return result[0:limit] | ||
| else: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo these functions provide barely any value over their bodies. Besides, I'm unsure what the purpose of
get_active_view_settingsis when in reality it falls back back to the window's settings?If you want to store data per window, you should probably do that explicitly (and all the time instead of only sometimes). However, I'm unsure if a window's settings are persisted on disk on exit, so this may actually result in leaking outdated data. An alternative would be a separate mapping that associates window-specific data with the window's id and is sufficiently cleared when the panel is closed. Usually I'd suggest storing that in the window command's instance variables, but since this plugin uses multiple commands that's not really an option.