0

我有“Super+Alt+left”来设置布局,使左窗格更宽(66%)的屏幕:

当前 ST2 布局

我还希望将相同的击键集中在左侧选项卡上,这样我就可以立即开始输入,而无需单击或 Ctrl + 0。

这是我尝试过的。我添加了一个新插件:

import sublime, sublime_plugin

class ExpandAndFocusLeftPane(sublime_plugin.TextCommand):
  def run(self, edit):
    self.view.run_command("focus_group", "args": {"group": 0})
    self.view.run_command("set_layout", "args": {
       "cols": [0.0, 0.66, 1.0],
      "rows": [0.0, 1.0],
      "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
      })

我将“Super+Alt+Left”绑定到这个新命令。

{
  "keys": ["super+alt+left"],
  "command": "expand_and_focus_left_pane",
  "args":
  {
    "cols": [0.0, 0.66, 1.0],
    "rows": [0.0, 1.0],
    "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
  }
},

但它仍然没有做我想做的事。有任何想法吗 ?

4

1 回答 1

1

First, you have to check if the "focus_group" and "set_layout" commands work as expected. Open the console (View->Show Console) and try this:

view.run_command("focus_group", "args": {"group": 0})

You'll get a:

  File "<string>", line 1
    view.run_command("focus_group", "args": {"group": 0})
                                          ^
SyntaxError: invalid syntax   

If you change it to

view.run_command("focus_group", {"group": 0}) 

it won't work. That's because "focus_group" and "set_layout" are window commands, so this will work:

window.run_command("focus_group", {"group": 0})
window.run_command("set_layout", { "cols": [0.0, 0.66, 1.0], "rows": [0.0, 1.0],  "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] })

So your plugin should extend sublime_plugin.WindowCommand and use self.window:

class ExpandAndFocusLeftPaneCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command("focus_group", {"group": 0})
        self.window.run_command("set_layout", {
           "cols": [0.0, 0.66, 1.0],
          "rows": [0.0, 1.0],
          "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
        })

And ExpandAndFocusLeftPane should be ExpandAndFocusLeftPaneCommand.

于 2013-05-09T13:58:31.883 回答