Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Draft copy function #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0 Add copy shortcut

- Add copy link functionality.

## 1.0.5 - Fixed search shortcut.

- Updated the search URL to reflect a recent Sourcegraph.com change.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Keyboard Shortcuts:
|---------------------------------|---------------------|------------------|
| Open file in Sourcegraph | <kbd>Option+A</kbd> | <kbd>Alt+A</kbd> |
| Search selection in Sourcegraph | <kbd>Option+S</kbd> | <kbd>Alt+S</kbd> |

| Copy link from Sourcegraph | <kbd>Option+C</kbd> | <kbd>Alt+C</kbd> |

## Settings

Expand Down
3 changes: 2 additions & 1 deletion keymaps/sourcegraph.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"atom-workspace": {
"alt-a": "sourcegraph:open",
"alt-s": "sourcegraph:search"
"alt-s": "sourcegraph:search",
"alt-c": "sourcegraph:copy"
}
}
32 changes: 31 additions & 1 deletion lib/sourcegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { CompositeDisposable } from 'atom'

const opn = require('opn')
const copy = require('copy')
const execa = require('execa')
const url = require('url')
const path = require('path')
Expand Down Expand Up @@ -97,7 +98,7 @@ async function open() {
}

// Open in browser.
opn(`${sourcegraphURL()}-/editor`
copy(`${sourcegraphURL()}-/editor`
+ `?remote_url=${encodeURIComponent(remoteURL)}`
+ `&branch=${encodeURIComponent(branch)}`
+ `&file=${encodeURIComponent(fileRel)}`
Expand Down Expand Up @@ -134,6 +135,35 @@ async function search() {
+ `&search=${encodeURIComponent(query)}`)
}

async function copy() {
let editor = atom.workspace.getActiveTextEditor()
if (!editor) {
return
}
let r = editor.getSelectedBufferRange()

const [remoteURL, branch, fileRel] = await repoInfo(editor.getPath())
if (remoteURL == "") {
return
}

// Open in browser.
opn(`${sourcegraphURL()}-/editor`
+ `?remote_url=${encodeURIComponent(remoteURL)}`
+ `&branch=${encodeURIComponent(branch)}`
+ `&file=${encodeURIComponent(fileRel)}`
+ `&editor=${encodeURIComponent("Atom")}`
+ `&version=${encodeURIComponent(VERSION)}`
+ `&start_row=${encodeURIComponent(r.start.row)}`
+ `&start_col=${encodeURIComponent(r.start.column)}`
+ `&end_row=${encodeURIComponent(r.end.row)}`
+ `&end_col=${encodeURIComponent(r.end.column)}`)
}

async function edit() {

}

export default {

config: {
Expand Down