Sublime Text 3 中带有拼写检查的弹出式拼写建议上下文菜单

Pop-up spelling suggestions context menu with spell checking in Sublime Text 3

我用以下代码对上下文菜单进行了键绑定:

command: context_menu

查看拼写建议,但按照它转到下一个单词并将光标放在单词末尾的方式进行操作是行不通的。但是,如果光标在单词内部或单词的开头,它就可以工作。有没有一种简单的方法可以说返回一个字符然后调出上下文菜单?

也可以让 ctrl+nctrl+p 在上下文菜单中工作。假设上下文菜单已关闭默认绑定。

最终使用了下面答案的建议,但只是略有不同的解决方案在命令 运行 之后将您带回到单词的开头我这样做了:

    {
"keys": ["ctrl+alt+w"],
// Force ability to bring up context menu
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
"args": {
    "commands": [
        // ["move", {"by":"word", "forward": false, "extend": false}],
        ["sbp_move_word", {"direction": -1}],
        ["context_menu"],
        ["move", {"by":"wordends", "forward": true, "extend": false}],
] }
},

// Do not use "find_under_expand" if selection is made
{
"keys": ["ctrl+alt+w"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": false } ],
"args": { "commands": [
            ["sbp_move_word", {"direction": -1}],
    // ["move", {"by":"word", "forward": false, "extend": false}],
    ["context_menu"], 
    ["move", {"by":"wordends", "forward": true, "extend": true}],
] }
},

出于某种原因,我在使用常规移动命令时遇到了问题,但应该也能正常工作,所以在 sublemacs 上面注释掉了它:

[1]

安装:

Chain Of Command



[2]

将此添加到您的键绑定中:

// Use "find_under_expand" if no selection is made
{
        "keys": ["ctrl+super+alt+t"],
        "command": "chain",
        "context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
        "args": {
                "commands": [
                        ["find_under_expand"],
                        ["select_word_beginning"],
                        ["context_menu"],
        ] }
},

// Do not use "find_under_expand" if selection is made
{
        "keys": ["ctrl+super+alt+t"],
        "command": "chain",
        "context": [ { "key": "selection_empty", "operator": "not_equal",   "operand": true } ],
        "args": {
                "commands": [
                        ["select_word_beginning"],
                        ["context_menu"],
        ] }
},

find_under_expand 命令将 select 插入符号处的单词,这使得 context_menu 能够始终如一地执行拼写建议。

第二个键绑定不使用 find_under_expand,因为这会导致您已经 selected 的文本的多个实例被 selected。



[3]

将其另存为 SelectWordBeginnings.py 在您的 /Packages/ 目录中的某处:

import sublime, sublime_plugin

class SelectWordBeginningCommand ( sublime_plugin.TextCommand ):

    def run ( self, edit ):

        view = self.view
        selections = view.sel()

        if len ( selections ) == 0:
            return

        selection = selections[0]

        if selection.a < selection.b:
            newSelection = sublime.Region ( selection.b, selection.a )
            view.selection.clear()
            view.selection.add ( newSelection )

此命令将反转 selected 区域,因此插入符号始终位于单词的开头。