-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Add support for activating and deactivating package-specific keymaps #8130
Conversation
atom.config.set("core.disabledKeymaps", ["package-with-keymaps-manifest"]) | ||
|
||
waitsForPromise -> | ||
atom.packages.activatePackage("package-with-keymaps-manifest") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Great feature! You thinking about adding UI in another PR or is this good enough? |
Yes! UI support is in atom/settings-view#610, forgot to put a link in when I added the other PR. |
This feature makes a lot of sense. Thanks for taking the time to add it! Right now, I can't tell if it works to add a package to the describe "when a package's keymaps are disabled and re-enabled after it is activated", ->
it "removes and re-adds the keymaps", ->
element1 = $$ -> @div class: 'test-1'
waitsForPromise ->
atom.packages.activatePackage("package-with-keymaps-manifest")
runs ->
atom.config.set("core.disabledKeymaps", ['package-with-keymaps-manifest'])
expect(atom.keymaps.findKeyBindings(keystrokes: 'ctrl-z', target: element1[0])).toHaveLength 0
atom.config.set("core.disabledKeymaps", [])
expect(atom.keymaps.findKeyBindings(keystrokes: 'ctrl-z', target: element1[0])[0].command).toBe 'keymap-1'
|
@maxbrunsfeld Good point, I knew I was missing something in the specs. Added. |
if value | ||
@activateKeymaps() | ||
else if not value | ||
@deactivateKeymaps() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to do this config-observing in the PackageManager
. Performance-wise, it would mean there'd be one observer instead of one for each package, and it would also be more consistent with the way we observe disabledPackages
. I think the code could be very similar to the code for observeDisabledPackages
.
Would you mind refactoring this code in that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that makes more sense, thanks for the suggestion.
Would you suggest splitting it into onDidChange for the observer and an initial config check for activation? I'm thinking that makes more sense too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you suggest splitting it into onDidChange for the observer and an initial config check for activation?
I don't have a strong opinion on that; go with whichever way makes the most sense as you're writing the code.
if value | ||
@activateKeymaps() | ||
else if not value | ||
@deactivateKeymaps() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the second if
, since its condition is the inverse of the first if
. How about this:
keymapIsDisabled = _.include(atom.config.get("core.disabledKeymaps") ? [], @name)
if keymapIsDisabled
@deactivateKeymaps()
else
@activateKeymaps()
I left some very minor additional feedback, and restarted the travis build because it failed for reasons unrelated to your change. Looks good! |
Alright! 🚢 💸 |
Add support for activating and deactivating package-specific keymaps
Thanks @tmunro and nice work. I want to put comment for setting name How about rename |
If you wanted to disable a specific keystroke, couldn't you just |
Yes, if you already have some Atom expertise. Even then, figuring out the right selectors gets tedious. If it gets @t9md to start including more bindings in his packages then it's totally worth it. ;-) |
I'm not so sure but I want some easy to use UI in settings-view to disable specific keymap by searching keystroke from Keybindings left menu on settings-view. But anyway, even if we won't introduce keystroke based disabling UI, I want to vote |
Yeah, that's a good point @t9md. It would be good to include How about /cc @atom/feedback |
I like |
|
Not 'without', since its originally 'with' keymap and disabled intentionally by user, so keyword 'disable' should be included to name.. but I agree naming is tough and but very important. |
Gotta say, I think |
Maybe |
Maybe reason for I don't think keymapdisabkedPackages awkward is because I'm not English native. So I will agree as long as keyword packages and disable included. 😄 |
|
👍 |
Adds support for activating and deactivating the keymaps for individual packages. Currently, there's no good way to quickly disable conflicting keymaps. Adding
unset!
entries for every binding in your own keymap is tedious and error-prone. This addsPackage
support for activating and deactivating keymaps, so you can easily choose which keymaps from which packages are important to you.See atom/settings-view#610 for UI support.
Related: atom/atom-keymap#82