atom-submode
activate granular CSS scope for keymap by trigger command
Development status
alpha
What's this?
- This package provides basic mechanism so that you can easily define submode.
- By adding predefined CSS class name to target element when trigger command was executed.
- When non-trigger command was executed, remove added CSS class name from target element.
- Currently target must be one of
atom-workspace
,atom-text-editor
oratom-pane
.
How to use
config.cson
1. Set configuration in your - Unlike normal atom packages, you must directly edit
config.cson
to add configuration. - define each submode spec under
submode.submode
object. - when submode is split by
.
and each segment classname is added to target element.- E.g. For
after-save
submode,atom.workspace.getElement().classList.add("after-save")
- E.g. For
after.move
submode,atom.workspace.getActiveTextEditor().element.classList("after", "move")
- E.g. For
submode:
submode:
"after-save": # submode name
target: "atom-workspace", # Must be one of ["atom-workspace", "atom-text-editor", "atom-pane"]
commands: [
"core:save" # List of commands which trigger this submode
],
"after.move":
target: "atom-text-editor",
commands: [
"core:move-up"
"core:move-down"
"core:move-right"
"core:move-left"
]
keymap.cson
2. Define keymap to use defined submode in your # after you invoke `core:save`, you can invoke `some:command` by keystroke `a`
'atom-workspace.after-save':
"a": "some:command"
# after you invoke `core:move-up/down/right/left`, you can invoke `some:command` by keystroke `a`
'atom-text-editor.after.move':
"a": "some:command"
Practical example
- If you are vim-mode-plus user
- And you want to select next tabs by
g t t t t
...(eacht
selectnext-tab
). - And you want to select previous tabs by
g T T T T
...(eachT
selectprevious-tab
). - You can do that with following
config.cson
andkeymap.cson
.
config.cson
submode:
submode:
"gt-mode":
target: "atom-pane"
commands: [
"vim-mode-plus:next-tab" # `g t`
"vim-mode-plus:previous-tab" # `g T`
]
keymap.cson
'atom-pane.gt-mode':
't': 'vim-mode-plus:next-tab'
'T': 'vim-mode-plus:previous-tab'
# To win over default `t`(vim-mode-plus:till) in text-editor scope.
'atom-pane.gt-mode atom-text-editor.vim-mode-plus':
't': 'vim-mode-plus:next-tab'
'T': 'vim-mode-plus:previous-tab'