From b3e9989cd20b3894b36e969b209d25ae06ab7ff7 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Thu, 16 Nov 2017 14:26:21 -0800 Subject: [PATCH] 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. --- src/core-uri-handlers.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core-uri-handlers.js b/src/core-uri-handlers.js index 2af00f610..b2ddbbc25 100644 --- a/src/core-uri-handlers.js +++ b/src/core-uri-handlers.js @@ -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 }) }