mirror of
https://github.com/atom/atom.git
synced 2026-02-04 19:54:59 -05:00
Add package to open links on ctrl-O
This commit is contained in:
2
src/packages/link/keymaps/links.cson
Normal file
2
src/packages/link/keymaps/links.cson
Normal file
@@ -0,0 +1,2 @@
|
||||
'body':
|
||||
'ctrl-O': 'link:open'
|
||||
16
src/packages/link/lib/link.coffee
Normal file
16
src/packages/link/lib/link.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
module.exports =
|
||||
activate: ->
|
||||
rootView.command 'link:open', ->
|
||||
editSession = rootView.getActivePaneItem()
|
||||
return unless editSession?
|
||||
|
||||
token = editSession.tokenForBufferPosition(editSession.getCursorBufferPosition())
|
||||
return unless token?
|
||||
|
||||
unless @selector?
|
||||
TextMateScopeSelector = require 'text-mate-scope-selector'
|
||||
@selector = new TextMateScopeSelector('markup.underline.link')
|
||||
|
||||
if @selector.matches(token.scopes)
|
||||
ChildProcess = require 'child_process'
|
||||
ChildProcess.spawn 'open', [token.value]
|
||||
1
src/packages/link/package.cson
Normal file
1
src/packages/link/package.cson
Normal file
@@ -0,0 +1 @@
|
||||
'main': 'lib/link'
|
||||
28
src/packages/link/spec/link-spec.coffee
Normal file
28
src/packages/link/spec/link-spec.coffee
Normal file
@@ -0,0 +1,28 @@
|
||||
RootView = require 'root-view'
|
||||
Editor = require 'editor'
|
||||
ChildProcess = require 'child_process'
|
||||
|
||||
describe "link package", ->
|
||||
[editor] = []
|
||||
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript.tmbundle', sync: true)
|
||||
atom.activatePackage('hyperlink-helper.tmbundle', sync: true)
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
atom.activatePackage('link')
|
||||
rootView.attachToDom()
|
||||
editor = rootView.getActiveView()
|
||||
editor.insertText("// http://github.com\n")
|
||||
|
||||
describe "when the cursor is on a link", ->
|
||||
it "opens the link using the 'open' command", ->
|
||||
spyOn(ChildProcess, 'spawn')
|
||||
editor.trigger('link:open')
|
||||
expect(ChildProcess.spawn).not.toHaveBeenCalled()
|
||||
|
||||
editor.setCursorBufferPosition([0,5])
|
||||
editor.trigger('link:open')
|
||||
|
||||
expect(ChildProcess.spawn).toHaveBeenCalled()
|
||||
expect(ChildProcess.spawn.argsForCall[0][1][0]).toBe "http://github.com"
|
||||
Reference in New Issue
Block a user