Skip to content

Instantly share code, notes, and snippets.

@johnjcamilleri
Last active April 17, 2019 09:28
Show Gist options
  • Save johnjcamilleri/aad68ae4a66c6074e98f75ee60c3fc6a to your computer and use it in GitHub Desktop.
Save johnjcamilleri/aad68ae4a66c6074e98f75ee60c3fc6a to your computer and use it in GitHub Desktop.
Atom selection mode feature

This is a hand-rolled alternative to the plugin https://github.com/jeffgran/atom-selection-mode.

My two major requests which that plugin doesn't support are:

  1. Do not deselect when tabbing
  2. Have an indicator when selection mode is on

My version does both these and is a bit simpler, but also less versatile/general. But it fills my need, and maybe someone else's too.

To get it to work, just paste the bits in the relevant files. Maybe I'll package it into a plugin one day.

# Toggle selection mode by adding class to current editor
atom.commands.add 'atom-text-editor', 'editor:toggle-selection-mode', ->
return unless editor = atom.workspace.getActiveTextEditor()
view = atom.views.getView(editor)
view.classList.toggle("selection-mode")
# Toggle selection mode
'atom-workspace atom-text-editor':
'ctrl-space': 'editor:toggle-selection-mode'
# When in selection mode, override cursor movements
'atom-workspace atom-text-editor.selection-mode':
'ctrl-n': 'core:select-down'
'ctrl-p': 'core:select-up'
'ctrl-f': 'core:select-right'
'ctrl-b': 'core:select-left'
'down': 'core:select-down'
'up': 'core:select-up'
'right': 'core:select-right'
'left': 'core:select-left'
// Show indicator when selection-mode is on (optional)
atom-text-editor.selection-mode::after {
position: absolute;
top: 1rem;
right: 1.5rem;
content: 'Ι';
color: fadeout(@text-color-warning, 20%);
font-size: 2rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment