atom / language-gfm

GitHub Flavored Markdown in Atom
MIT License
101 stars 107 forks source link

Request: Command to insert URL #102

Open bobrocke opened 9 years ago

bobrocke commented 9 years ago

Would it be possible for you to add a command that would replace the currently selected text with:

[$SelectedText$]($ClipboardContents$)

That would allow the user to copy a URL, select the desired anchor text, and then initiate the command.

izuzak commented 9 years ago

@bobrocke The nice thing about Atom is that you can add these commands yourself, through the init.coffee file. You don't really need to wait for a package to implement this (especially if it's something you need right now, and other users don't feel strongly about).

Here's what you might put in your init.coffee to add such a command (warning: I haven't tested this much):

atom.commands.add 'atom-text-editor', 'markdown:paste-as-url', ->
  return unless editor = atom.workspace.getActiveTextEditor()

  selection = editor.getLastSelection()
  cliptext = atom.clipboard.read()

  selection.insertText("[#{selection.getText()}](#{cliptext})")

Now reload Atom and you should see a "Markdown: paste as url" command in the command palette. Once you have a command, you can add a keybinding for it.

Does that help?

bobrocke commented 9 years ago

Yes, in fact I'm working on my own personal utilities package and can put that in it while a broader solution is considered.

programster commented 9 years ago

@izuzak the init.coffee link appears to not be working. Perhaps you wanted this?

izuzak commented 9 years ago

@programster It was working at the time the comment was created -- you'll notice that the init.coffee file in the docs was updated and renamed since then, which broke the link. I've updated it in my comment so that it points to https://atom.io/docs/latest/hacking-atom-the-init-file, thanks for pointing it out.

izuzak commented 9 years ago

@atom/feedback Do some other language-* packages add commands? I think this would be useful to add for GFM, but not sure if this package should be the place to do it or if a new package would be a better choice. I think it make sense to add it here, but wondering if you have any thoughts or know of examples?

lee-dohm commented 9 years ago

I don't know of any language packages that add commands off the top of my head, no. But I don't think it would be that big of a deal. I think assigning keybindings might get challenging though.