Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 3e13ce2

Browse files
author
Stephen Gutekanst
committed
fix: make line decoration link opening match Sourcegraph behavior
Prior to this change, clicking links that are provided by a Sourcegraph extension would cause them to open in the same page. This is in contrast to what clicking the same link on Sourcegraph does: opens in a new tab if not relative. Fixes sourcegraph/sourcegraph-extension-api#70
1 parent 893768e commit 3e13ce2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libs/code_intelligence/extensions.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ export const applyDecoration = (
176176
const link = document.createElement('a')
177177
link.className = 'sourcegraph-extension-element'
178178
link.setAttribute('href', url)
179+
180+
// External URLs should open in a new tab, whereas relative URLs
181+
// should not.
182+
link.setAttribute('target', /^https?:\/\//.test(url) ? '_blank' : undefined)
183+
179184
link.style.color = decoration.after!.color || null
180185
link.appendChild(e)
181186
return link

0 commit comments

Comments
 (0)