关闭滚动列表时崇高文字自动完成窗口关闭 [英] Sublime Text autocomplete window closes when scrolling off the list

查看:247
本文介绍了关闭滚动列表时崇高文字自动完成窗口关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在滚动的自动完成列表<大骨节病>高达或<大骨节病>下,如果你走得太远在任一方向(例如,有没有更多的建议),该列表将关闭。

When scrolling the autocomplete list with up or down, if you go too far in either direction (e.g. there are no more suggestions), the list will close.

我要的行为是无法到达终点,而不是关闭时,列表总结。

The behavior I want is to have the list wrap when reaching the end instead of close.

这是容易向下滚动修正通过指派此热键:

This is easy to fix with downward scrolling by assigning this hotkey:

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

这是因为 auto_complete 命令的内置功能,每次它调用的时候,这就是为什么热键作品向下滚动。

That's because the auto_complete command has built-in functionality to scroll downward each time it's invoked, which is why the hotkey works.

...但向上滚动是不同的。我尝试过大约20个不同的热键和宏观的组合,但没有成功。

...But upward scrolling is different. I've tried about 20 different hotkey and macro combinations with no success.

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

I'm almost certain the only way to achieve this behavior is with a plugin, but unfortunately my Python skill level is nil.

如果它的事项,我手动调用自动完成与<大骨节病> CTRL + <大骨节病>空格(自动弹出被禁用)。

If it matters, I'm manually invoking autocomplete with ctrl+space (the automatic popup is disabled).

我用崇高的文本2。

推荐答案

最好的解决办法:使用的 auto_complete_cycle 的设置(2015年新增3月26日):

Best solution: use auto_complete_cycle settings (added 26 March 2015):

崇高文字新版本有一个新的设置所谓的 auto_complete_cycle 实现此行为。其设置为true通过自动完成结果进行迭代。

Sublime Text new version relased on 24 March 2015 has a new setting called auto_complete_cycle that implement this behaviour. Set it to true to iterate through the autocomplete results.

"auto_complete_cycle": true

最差的老办法:这个定义插件

我刚才提出这个插件上行之有效的崇高文字3 的中的 Linux Mint的的。我没有的崇高文字2 的测试,但认为这是同一个插件系统,所以,应该在该版本的工作了。解决方法使用,这不是太pretty但工程。

I have just made this plugin that works well on Sublime Text 3 in Linux Mint. I have not tested it in Sublime Text 2 but think the plugin system it's the same, so, it should work on that version too. The workaround used it's not too pretty but 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

为了使插件使用的工具>新插件的并粘贴code。然后将其保存的软件包/用户的文件夹中。您可以使用的 preferences>浏览包的找到的软件包的floder,这里面的用户文件夹的位置。

To make the plugin use Tools>new Plugin and paste the code. Then save it in Packages/User folder. You can use Preferences>Browse Packages to find the Packages floder, inside which the User folder is located.

要使它工作,我加入到我的用户的键绑定文件的这种绑定(第二这是你自己的绑定):

To make it work I added to my user key-bindings file this bindings (the second it's 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"
    }]
}

编辑:这是一个例子的结果:

this is an example result:

这篇关于关闭滚动列表时崇高文字自动完成窗口关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆