Keep text selected after key command


#1

Hi all,

I have key commands for html font styling like bold, italicize etc. So I select text, press my key then it adds tags around the text with the cursor at the end of it.

However, I would like to make it to where even after the command is executed, the text I selected STAYS selected after the key command. That way, I can press other commands adding further styling if need be. So in other words, I’d like to do the following…

  • I select the following text: Lorem Ipsum…
  • I press “f1” to add bold and it now shows as: Lorem Ipsum
  • I’d like for “Lorem Ipsum” to still be selected…
  • Then I could press “f2” to add italics: Lorem Ipsum

This possible?

init.coffee

atom.commands.add ‘atom-text-editor’,

‘editor:wrap-with-strong’: ->
editor = atom.workspace.getActiveTextEditor()
for selection in editor.getSelections()
textToWrap = selection.getText()
selection.insertText("#{textToWrap}")

keymap.cson

‘atom-text-editor’:
‘f1’: ‘editor:wrap-with-strong’


#2

Whoops. It’s my first post here and didn’t realize my html tags would be applied. Here is the code below as I originally meant it.

  • I select the following text: Lorem Ipsum…
  • I press “f1” to add bold and it now shows as: <strong>Lorem Ipsum<strong>
  • I’d like for “Lorem Ipsum” to still be selected…
  • Then I could press “f2” to add italics: <strong><em>Lorem Ipsum</em></strong>

init.coffee
atom.commands.add ‘atom-text-editor’,

‘editor:wrap-with-strong’: ->
editor = atom.workspace.getActiveTextEditor()
for selection in editor.getSelections()
textToWrap = selection.getText()
selection.insertText("<strong>#{textToWrap}</strong>")

keymap.cson
‘atom-text-editor’:
‘f1’: ‘editor:wrap-with-strong’