gpt4 book ai didi

autocomplete - 滚动列表时关闭 Sublime Text 自动完成窗口

转载 作者:行者123 更新时间:2023-12-03 13:34:33 24 4
gpt4 key购买 nike

向上或向下滚动自动完成列表时,如果您在任一方向上走得太远(例如,没有更多建议),列表将关闭。

我想要的行为是在到达末尾而不是关闭时让列表换行。

通过分配此热键,可以通过向下滚动轻松解决此问题:

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

那是因为 auto_complete命令具有每次调用时向下滚动的内置功能,这就是热键起作用的原因。

...但向上滚动是不同的。我尝试了大约 20 种不同的热键和宏组合,但均未成功。

我几乎可以肯定实现这种行为的唯一方法是使用插件,但不幸的是我的 Python 技能水平为零。

如果这很重要,我将使用 ctrl+space 手动调用自动完成(自动弹出窗口已禁用)。

我正在使用 Sublime Text 2。

最佳答案

最佳解决方案:使用 auto_complete_cycle 设置(2015 年 3 月 26 日添加):

请使用这个新的简单解决方案,而不是 python 插件

2015 年 3 月 24 日发布的 Sublime Text 新版本有一个新的 名为 auto_complete_cycle 的设置实现这种行为。将其设置为 true 以遍历自动完成结果。

"auto_complete_cycle": true

最糟糕的旧解决方案:这个自定义插件

我刚刚制作了这个插件,它在 Linux Mint 的 Sublime Text 3 上运行良好。我没有在 Sublime Text 2 中测试过它,但认为插件系统是一样的,所以它也应该在那个版本上工作。使用的解决方法不是太漂亮但有效。
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

要制作插件,请使用工具>新插件并粘贴代码。然后将其保存在 Packages/User 文件夹中。您可以使用 Preferences>Browse Packages 来查找 Packages 文件夹,User 文件夹位于该文件夹中。

为了使它工作,我在我的用户键绑定(bind)文件中添加了这个绑定(bind)(第二个是你自己的绑定(bind)):
{
"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"
}]
}

编辑:这是一个示例结果:

Result

关于autocomplete - 滚动列表时关闭 Sublime Text 自动完成窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25263791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com