2013-08-28 17 views
1

在Sublime Text 3中,我嘗試使用同樣的捷徑,但有不同的背景。基本上,我想在其三個可能的值之間交替設置draw_white_spacenone,selectionall我無法得到這個工作:在Sublime Text(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的快捷方式將僅在第一次使用。它和其他人將在那之後工作。

我注意到的另一件事是我的設置文件不會更改draw_white_space值,當快捷方式工作(包括三個單獨的快捷方式)。我認爲這可能是默認行爲 - 設置更改可能是每個會話 - 並沒有問題。但是,我完全刪除了該設置,並且它仍然是相同的行爲。

我正在更改通過Preferences打開的文件| Key Bindings - User菜單,其中打開<Sublime Text>\Data\Packages\User\Default (Windows).sublime-keymap文件。

任何想法?我做錯了什麼或缺少什麼?

+0

不知道爲什麼'{ 「關鍵」: 「setting.draw_white_space」, 「經營者」: 「NOT_EQUAL」, 「操作數」: 「all」}'總是'true'。 – Kabie

回答

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

+0

哇,謝謝!這很棒,正是我期待的!我不知道是什麼原因導致了我的原始問題,但是這比我預期的更好地解決了我的請求! – wasatchwizard

+0

再次感謝@skuroda!我把它磨光了(用我所知道的關於創建Sublime Text插件到目前爲止)並將其放在github上。它確實是我想要的,我也學到了很多關於創建插件的知識!再次感謝! https://github.com/kodybrown/SublimeCycleWhiteSpace – wasatchwizard

相關問題