Sublime Text autocomplete closes when scrolling through a list

When scrolling through the autocomplete list using up or down , if you go too far in any direction (for example, there are no more offers), the list closes.

The behavior I want is to wrap the list when reaching the end, not closing.

This can be easily fixed by scrolling down by assigning this hotkey:

{ "keys": ["down"], "command": "auto_complete", "context": [ { "key": "auto_complete_visible" } ] }, 

This is because the auto_complete command has built-in functions to scroll down each time it is called, so the hotkey works.

... but the upward scrolling is different. I tried about 20 different keyboard shortcuts and macros without success.

I am pretty sure that the only way to achieve this behavior is with a plugin, but unfortunately my Python skill level is zero.

If that matters, I manually call autocomplete with ctrl + space (auto popup is disabled).

I am using Sublime Text 2.

+7
autocomplete sublimetext2 sublimetext sublimetext3
source share
1 answer

Best solution: use auto_complete_cycle parameters (added March 26, 2015):

Please use this new easy solution, not the python plugin

The new version of Sublime Text released on March 24, 2015 has a new parameter called auto_complete_cycle that implements this behavior. Set to true to repeat autocomplete results.

 "auto_complete_cycle": true 

Worst old solution: this custom plugin

I just made this plugin that works well on Sublime Text 3 in Linux Mint. I have not tested it in Sublime Text 2, but I think the plugin system is the same, so it should work on this version too. The workaround used it is not too pretty, but it works.

 import sublime, sublime_plugin class UpArrowInAutoCompleteCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.settings().set('autoCompleteFlag',True) self.view.settings().set('initialPoint', self.view.sel()[0].begin()) """ Move one line up """ self.view.run_command('move', {"by": "lines", "forward": False}); """ Auto-complete was opened and up arrow was pressed, so if the cursor changes (on_selection_modified will be triggered) we have gone outside the list. If we were not in the first element on_selection_modified will not be triggered, so we turn of the flag""" sublime.set_timeout(lambda: self.view.settings().set('autoCompleteFlag', False),300) class AutoCompleteSelectionModifiedTriggerCommand(sublime_plugin.EventListener): def on_selection_modified(self, view): if view.settings().get('autoCompleteFlag'): """ If the up arrow was pressed and on_selection_modified has been triggered, then we know that we were in the first element of the list and we hitted the up arrow""" view.settings().set('autoCompleteFlag', False) initialPoint = view.settings().get('initialPoint') """ We don't know how many words the auto_complete has, so, in order to calculate that number, we move down in the list till we get outside the list. After that we make the list appear again and move down n-1 times to go (and stay) to the last line """ view.sel().clear() view.sel().add(initialPoint) view.run_command('auto_complete') numLines = 0 while view.sel()[0].begin() == initialPoint: view.run_command('move', {"by": "lines", "forward": True}) numLines += 1 if numLines == 401: return if numLines == 0: return view.sel().clear() view.sel().add(initialPoint) view.run_command('auto_complete') numLine = 0 while numLine < (numLines-1): view.run_command('move', {"by": "lines", "forward": True}) numLine += 1 

So that the plugin uses Tools> the new plugin and inserts the code. Then save it in the Packages / User folder. You can use Settings> Browse Packages to find the Packages box, inside which the userโ€™s folder is located.

To do this, I added these bindings to my user key bindings file (the second is your own binding):

 { "keys": ["up"], "command": "up_arrow_in_auto_complete", "context": [{ "key": "auto_complete_visible", "operator": "equal", "operand": true }] }, { "keys": ["down"], "command": "auto_complete", "context": [{ "key": "auto_complete_visible" }] } 

Edit: this is an example result:

Result

+10
source share

All Articles