Translate line and column numbers from URI handlers

The URI query string should specify line and column numbers as a user
would, starting at 1, while the Atom API starts at 0.
This commit is contained in:
Michelle Tilley
2017-11-16 14:26:21 -08:00
parent 0192545f3d
commit b3e9989cd2

View File

@@ -1,9 +1,16 @@
// Converts a query string parameter for a line or column number
// to a zero-based line or column number for the Atom API.
function getLineColNumber (numStr) {
const num = parseInt(numStr || 0, 10)
return Math.max(num - 1, 0)
}
function openFile (atom, {query}) {
const {filename, line, column} = query
atom.workspace.open(filename, {
initialLine: parseInt(line || 0, 10),
initialColumn: parseInt(column || 0, 10),
initialLine: getLineColNumber(line),
initialColumn: getLineColNumber(column),
searchAllPanes: true
})
}