6

我开始自定义 Atom 编辑器,并且在尝试更改 Tree View:Toggle 的键映射时遇到了困难。

我把它放在我的用户 keycap.cson 文件中:

'.editor': 'ctrl-t': 'Tree View:Toggle'

但它不起作用。

查看 Preferences->Keybindings 我看到它按预期列出:

ctrl-t Tree View:Toggle User .editor

我做错了什么?

更新:

更改为:

'.editor': 'ctrl-t': 'tree-view:toggle'

没有解决问题。

Key Binding Resolver 显示该命令已被识别,但它没有切换树视图。看这个截图:

http://cl.ly/image/3A2X1p350v2Q

对此还有其他想法吗?

4

3 回答 3

7

I went through the same problem! It was a pain in the ass because i needed to use my own shortcuts but atom's keybinding are different from my latin-qwerty-keyboard, so while playing around with atom and looking for some good information, i came out with this solution:

Problem:

When i type in my windows Ctrl-Alt-\ Atom's keybinding is Ctrl-Alt-]

Or if i want '@' i need to type Ctrl-Alt-q but Atom's keybinding does this 'autoflow:reflow-selection' instead.

Solution:

1._ Go to Settings->Keybindings. Once you're there, in the search bar, find the keybinding you want to change. For example if i want to change Ctrl-Alt-q, so i type: Q and it'll filter all keybindings with this letter.

2._Then to modify it, click int the copy&paste small-icon next to the keybinding you want to modify, it is at Keystroke column. (it will copy the code lines that you need so that you can modify it)

3._ Once you copied the keybinding, go to File->Open Your Keymap and it'll open a tab with the keymap.cson file. Put your cursor at the end and paste there the lines you copied in step#2. It should show something like this:

'.platform-win32 .editor, .platform-linux .editor':
  'ctrl-alt-q': 'autoflow:reflow-selection'

4._ Now you can change atom's behavior. I'll erase 'autoflow:reflow-selection' and write 'unset!' so that it shows the arroba.

'.platform-win32 .editor, .platform-linux .editor':
  'ctrl-alt-q': 'unset!'

Now when i type Ctrl-Alt-q in atom editor it shows the arroba, finally! If you want it to do something else, instead of writting 'unset!' you just need to put whatever you want it to do.

Note: If you want to know the atom's keybindings so that you can change some of them, use the keybinding resolver, go to Packages->Keybinding Resolver->Toggle.

Here i post the changes i did in my keymap.cson in order to use my atom editor with my latin-qwerty-keyboard.

'atom-workspace atom-text-editor:not([mini])':
  "ctrl-alt-[": "unset!",
  "ctrl-alt-]": "unset!",
  'ctrl-/': 'unset!'
  'ctrl-7': 'editor:toggle-line-comments'
  'ctrl-alt-8': 'tree-view:recursive-collapse-directory'
  'ctrl-alt-8': 'editor:fold-current-row'
  'ctrl-alt-9': 'editor:unfold-current-row'
'.platform-win32 .editor, .platform-linux .editor':
  'ctrl-alt-q': 'unset!'
'.platform-win32 .find-and-replace, .platform-linux .find-and-replace':
  'ctrl-alt-/': 'unset!'
  'ctrl-alt-7': 'find-and-replace:toggle-regex-option'
'.platform-win32 .project-find, .platform-linux .project-find':
  'ctrl-alt-/': 'unset!'
  'ctrl-alt-7': 'project-find:toggle-regex-option'

Cheers!

于 2015-01-16T20:08:28.367 回答
4

这很容易解决。您没有正确格式化命令的名称。它应该如下所示:

'.editor':
  'ctrl-t': 'tree-view:toggle'

将来,如果事情没有按预期工作,请尝试检查您知道正在工作的现有开源软件包,看看是否能找到不匹配的地方。例如,您可以转到树视图的键盘映射文件,tree-view.cson以查看它们是如何格式化的。


进一步的改进

您可能会注意到,因为您定义的键绑定与editor相关联,如果您将Tree View放在焦点上,则不会触发您的键绑定。同样,查看上面的文件,您将看到一种改进方法。将键绑定绑定到平台.platform-darwin(或任何适合您的平台),以便无论编辑器的哪个元素处于焦点,都会触发它。

'.platform-darwin':
  'ctrl-t': 'tree-view:toggle'

当然,这提出了一个不同的问题。现在,当编辑器处于焦点时,现有的键绑定 foreditor:transpose将优先,因为它更具体的 CSS 类(即.editor)。因此,当编辑器处于焦点时,树视图现在不会被切换。解决此问题的最简单方法是为编辑器添加键绑定:

'.platform-darwin':
  'ctrl-t': 'tree-view:toggle'

'.editor':
  'ctrl-t': 'tree-view:toggle'

现在无论是编辑器还是树视图都处于焦点位置,但仍会触发切换。


最后的想法

使用键绑定时的另一条建议是使用Keybinding Resolver。您可以使用cmd-.. 如果您这样做并尝试按下ctrl-t,您会注意到您添加的键绑定显示(以绿色突出显示)。您还会注意到您的键绑定正在禁止另一个键绑定,editor:transpose. 考虑使用不同的键绑定。

Atom 的美妙之处在于它的可定制性,只需确保您了解定制的权衡。

于 2014-04-02T21:36:43.767 回答
2

好吧,我对 ATOM 也有同样的问题,我几乎要放弃了!我在 Windows 8 PC 上有 ATOM workink。

  1. 如果您修改了 keymap.cson,请重新启动编辑器。
  2. 如果您更改任何键绑定的值,请为您更改的函数创建一个新的键绑定。例如

我对@有问题,我用这条线修复它

使用 Packages>KeyBinding 解析器实用程序,我得到:

ctrl-alt-q 是我的 @ 键序列

使用 KeyBinding 实用程序我得到: ctrl-alt-q 执行 autoflow:reflow-selection 命令

'.platform-win32 atom-text-editor, .platform-linux atom-text-editor': 'ctrl-alt-q': 'unset!', 'ctrl-alt-7': 'autoflow:reflow-selection'

首先我取消了我的键绑定,然后我为我想要覆盖的命令发明了一个新的。

希望它对你有用

于 2015-06-02T05:59:20.247 回答