mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Merge pull request #16940 from BoykoAlex/atom-links
Support `atom` protocol links when links are handled
This commit is contained in:
@@ -61,7 +61,7 @@ describe('WindowEventHandler', () => {
|
||||
})
|
||||
)
|
||||
|
||||
describe('when a link is clicked', () =>
|
||||
describe('when a link is clicked', () => {
|
||||
it('opens the http/https links in an external application', () => {
|
||||
const {shell} = require('electron')
|
||||
spyOn(shell, 'openExternal')
|
||||
@@ -93,7 +93,24 @@ describe('WindowEventHandler', () => {
|
||||
windowEventHandler.handleLinkClick(fakeEvent)
|
||||
expect(shell.openExternal).not.toHaveBeenCalled()
|
||||
})
|
||||
)
|
||||
|
||||
it('opens the "atom://" links with URL handler', () => {
|
||||
const uriHandler = windowEventHandler.atomEnvironment.uriHandlerRegistry
|
||||
expect(uriHandler).toBeDefined()
|
||||
spyOn(uriHandler, 'handleURI')
|
||||
|
||||
const link = document.createElement('a')
|
||||
const linkChild = document.createElement('span')
|
||||
link.appendChild(linkChild)
|
||||
link.href = 'atom://github.com'
|
||||
jasmine.attachToDOM(link)
|
||||
const fakeEvent = {target: linkChild, currentTarget: link, preventDefault: () => {}}
|
||||
|
||||
windowEventHandler.handleLinkClick(fakeEvent)
|
||||
expect(uriHandler.handleURI).toHaveBeenCalled()
|
||||
expect(uriHandler.handleURI.argsForCall[0][0]).toBe('atom://github.com')
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a form is submitted', () =>
|
||||
it("prevents the default so that the window's URL isn't changed", () => {
|
||||
|
||||
@@ -242,8 +242,12 @@ class WindowEventHandler {
|
||||
handleLinkClick (event) {
|
||||
event.preventDefault()
|
||||
const uri = event.currentTarget && event.currentTarget.getAttribute('href')
|
||||
if (uri && (uri[0] !== '#') && /^https?:\/\//.test(uri)) {
|
||||
this.applicationDelegate.openExternal(uri)
|
||||
if (uri && uri[0] !== '#') {
|
||||
if (/^https?:\/\//.test(uri)) {
|
||||
this.applicationDelegate.openExternal(uri)
|
||||
} else if (uri.startsWith('atom://')) {
|
||||
this.atomEnvironment.uriHandlerRegistry.handleURI(uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user