1

Sublime Text 3 では、同じショートカットを使用して設定の値を変更しようとしていますが、コンテキストが異なります。基本的に、設定を、draw_white_space、 の 3 つの可能な値の間で交互に変更したいと考えています。noneselectionall

3 つの個別のショートカット/キーマップを使用して、設定を簡単に変更できます。これがそのコードです(動作中):

{
    "keys": ["ctrl+e", "ctrl+w"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "all",
    }
},
{
    "keys": ["ctrl+e", "ctrl+q"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "none",
    }
},
{
    "keys": ["ctrl+e", "ctrl+s"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "selection",
    }
}

しかし、私が本当に欲しいのは、押し["ctrl+e", "ctrl+w"]て、可能な値ごとに交互に表示できるようにすることです。はい、使い慣れた Visual Studio のショートカットです。

動作するように見えるものを作成しましたが、動作しません。少なくとも私が望む方法ではありません。これがそのコードです(壊れています):

{
    "keys": ["ctrl+e", "ctrl+w"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "none",
    },
    "context": [
        { "key": "setting.draw_white_space", 
          "operator": "equal", "operand": "all" }
    ]
},
{
    "keys": ["ctrl+e", "ctrl+w"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "selection",
    },
    "context": [
        { "key": "setting.draw_white_space",
          "operator": "equal", "operand": "none" }
    ]
},
{
    "keys": ["ctrl+e", "ctrl+w"],
    "command": "set_setting",
    "args": {
        "setting": "draw_white_space",
        "value": "all",
    },
    "context": [
        { "key": "setting.draw_white_space",
          "operator": "equal", "operand": "selection" }
    ]
}

私は自分のコンテキストをテストしたので、それらが機能することを知っています。たとえばall、設定ファイルで手動で設定すると、チェックするショートカットallは初回のみ機能します。その後、それも他のものも機能しません。

私が気付いたもう 1 つのことはdraw_white_space、ショートカットが機能するときに設定ファイルの値が変更されないことです (3 つの個別のショートカットを含む)。それがデフォルトの動作である可能性があると思いました-設定の変更はセッションごとに行われる可能性があります-そしてそれは問題ありません。しかし、設定を完全に削除しましたが、それでも同じ動作です。

Preferences|で開いたファイルを変更しています。ファイルKey Bindings - Userを開いたメニュー。<Sublime Text>\Data\Packages\User\Default (Windows).sublime-keymap

何か案は?私は何か間違っているか、何かが欠けていますか?

4

1 に答える 1

2

あなたが望むものではないかもしれませんが、非常に単純なプラグインでその動作を得ることができます.

import sublime
import sublime_plugin

class CycleDrawWhiteSpaceCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        white_space_type = view.settings().get("draw_white_space")

        if white_space_type == "all":
            view.settings().set("draw_white_space", "none")
        elif white_space_type == "none":
            view.settings().set("draw_white_space", "selection")
        else:
            view.settings().set("draw_white_space", "all")

プラグインを保存したら、キーバインディングをcycle_draw_white_space

于 2013-08-30T03:16:58.707 に答える