Use "shell.openExternal(url)" to open links in external browsers.

This commit is contained in:
Cheng Zhao
2013-05-20 10:05:19 +08:00
parent 7cb6801ce8
commit 8be54136ed
4 changed files with 18 additions and 19 deletions

View File

@@ -232,22 +232,22 @@ describe "Window", ->
describe "when a link is clicked", ->
it "opens the http/https links in an external application", ->
ChildProcess = require 'child_process'
spyOn(ChildProcess, 'spawn')
shell = require 'shell'
spyOn(shell, 'openExternal')
$("<a href='http://github.com'>the website</a>").appendTo(document.body).click().remove()
expect(ChildProcess.spawn).toHaveBeenCalled()
expect(ChildProcess.spawn.argsForCall[0][1][0]).toBe "http://github.com"
expect(shell.openExternal).toHaveBeenCalled()
expect(shell.openExternal.argsForCall[0]).toBe "http://github.com"
ChildProcess.spawn.reset()
shell.openExternal.reset()
$("<a href='https://github.com'>the website</a>").appendTo(document.body).click().remove()
expect(ChildProcess.spawn).toHaveBeenCalled()
expect(ChildProcess.spawn.argsForCall[0][1][0]).toBe "https://github.com"
expect(shell.openExternal).toHaveBeenCalled()
expect(shell.openExternal.argsForCall[0]).toBe "https://github.com"
ChildProcess.spawn.reset()
shell.openExternal.reset()
$("<a href=''>the website</a>").appendTo(document.body).click().remove()
expect(ChildProcess.spawn).not.toHaveBeenCalled()
expect(shell.openExternal).not.toHaveBeenCalled()
ChildProcess.spawn.reset()
shell.openExternal.reset()
$("<a href='#scroll-me'>link</a>").appendTo(document.body).click().remove()
expect(ChildProcess.spawn).not.toHaveBeenCalled()
expect(shell.openExternal).not.toHaveBeenCalled()

View File

@@ -125,7 +125,7 @@ window.handleEvents = ->
return if location[0] is '#'
if location.indexOf('https://') is 0 or location.indexOf('http://') is 0
require('child_process').spawn('open', [location])
require('shell').openExternal(location)
false
window.handleDragDrop = ->

View File

@@ -12,5 +12,4 @@ module.exports =
@selector = new TextMateScopeSelector('markup.underline.link')
if @selector.matches(token.scopes)
ChildProcess = require 'child_process'
ChildProcess.spawn 'open', [token.value]
require('shell').openExternal token.value

View File

@@ -1,6 +1,6 @@
RootView = require 'root-view'
Editor = require 'editor'
ChildProcess = require 'child_process'
shell = require 'shell'
describe "link package", ->
[editor] = []
@@ -17,12 +17,12 @@ describe "link package", ->
describe "when the cursor is on a link", ->
it "opens the link using the 'open' command", ->
spyOn(ChildProcess, 'spawn')
spyOn(shell, 'openExternal')
editor.trigger('link:open')
expect(ChildProcess.spawn).not.toHaveBeenCalled()
expect(shell.openExternal).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"
expect(shell.openExternal).toHaveBeenCalled()
expect(shell.openExternal.argsForCall[0]).toBe "http://github.com"