微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

滚动列表时,Sublime Text自动完成窗口将关闭

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

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

通过分配此热键,可以通过向下滚动轻松修复:

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

这是因为auto_complete命令具有内置功能,可以在每次调用时向下滚动,这就是热键的工作原理.

……但向上滚动是不同的.我尝试了大约20种不同的热键和宏组合但没有成功.

我几乎可以肯定,实现此行为的唯一方法是使用插件,但不幸的是我的Python技能级别为零.

如果重要的话,我用ctrl空间手动调用自动完成(自动弹出窗口被禁用).

我正在使用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',"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',"forward": True})
                numLine += 1

要使插件使用工具>新插件并粘贴代码.然后将其保存在Packages / User文件夹中.您可以使用“首选项”>“浏览包”查找“用户文件夹所在的“包”文件夹.

为了使它工作,我添加到我的用户密钥绑定文件这个绑定(第二个它是你自己的绑定):

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

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

原文地址:https://www.jb51.cc/html/226015.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐