Handle file paths that contain line numbers

This commit is contained in:
Matt Colyer
2013-09-11 15:07:29 -07:00
parent 7aa87adf8d
commit e8838e3bd0
5 changed files with 27 additions and 15 deletions

View File

@@ -201,8 +201,8 @@ class AtomApplication
# Public: Opens a single path, in an existing window if possible.
#
# * options
# + pathsToOpen:
# The array of file paths to open
# + pathToOpen:
# The file path to open
# + pidToKillWhenClosed:
# The integer of the pid to kill
# + newWindow:
@@ -210,18 +210,21 @@ class AtomApplication
# + devMode:
# Boolean to control the opened window's dev mode.
openPath: ({pathToOpen, pidToKillWhenClosed, newWindow, devMode}={}) ->
[pathToOpen, initialLine] = pathToOpen.split(':')
initialLine -= 1 # Convert line numbers to a base of 0
unless devMode
existingWindow = @windowForPath(pathToOpen) unless pidToKillWhenClosed or newWindow
if existingWindow
openedWindow = existingWindow
openedWindow.openPath(pathToOpen)
openedWindow.openPath(pathToOpen, initialLine)
else
bootstrapScript = 'window-bootstrap'
if devMode
resourcePath = global.devResourcePath
else
resourcePath = @resourcePath
openedWindow = new AtomWindow({pathToOpen, bootstrapScript, resourcePath, devMode})
openedWindow = new AtomWindow({pathToOpen, initialLine, bootstrapScript, resourcePath, devMode})
if pidToKillWhenClosed?
@pidsToOpenWindows[pidToKillWhenClosed] = openedWindow

View File

@@ -18,7 +18,7 @@ class AtomWindow
isSpec: null
constructor: (settings={}) ->
{@resourcePath, pathToOpen, @isSpec} = settings
{@resourcePath, pathToOpen, initialLine, @isSpec} = settings
global.atomApplication.addWindow(this)
@setupNodePath(@resourcePath)
@@ -41,7 +41,7 @@ class AtomWindow
@browserWindow.once 'window:loaded', => @loaded = true
@browserWindow.loadUrl "file://#{@resourcePath}/static/index.html"
@openPath(pathToOpen)
@openPath(pathToOpen, initialLine)
setupNodePath: (resourcePath) ->
paths = [
@@ -104,12 +104,12 @@ class AtomWindow
@browserWindow.on 'blur', =>
@browserWindow.focusOnWebView()
openPath: (pathToOpen) ->
openPath: (pathToOpen, initialLine) ->
if @loaded
@focus()
@sendCommand('window:open-path', pathToOpen)
@sendCommand('window:open-path', {pathToOpen, initialLine})
else
@browserWindow.once 'window:loaded', => @openPath(pathToOpen)
@browserWindow.once 'window:loaded', => @openPath(pathToOpen, initialLine)
createContextMenu: ->
@contextMenu = new Menu

View File

@@ -80,7 +80,7 @@ class EditSession
@setScrollLeft(@state.get('scrollLeft'))
registerEditSession = true
else
{buffer, displayBuffer, tabLength, softTabs, softWrap, suppressCursorCreation} = optionsOrState
{buffer, displayBuffer, tabLength, softTabs, softWrap, suppressCursorCreation, initialLine} = optionsOrState
@id = guid.create().toString()
displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrap})
@state = site.createDocument
@@ -95,7 +95,10 @@ class EditSession
@setDisplayBuffer(displayBuffer)
if @getCursors().length is 0 and not suppressCursorCreation
position = _.last(@getRemoteCursors())?.getBufferPosition() ? [0, 0]
if initialLine
position = [initialLine, 0]
else
position = _.last(@getRemoteCursors())?.getBufferPosition() ? [0, 0]
@addCursorAtBufferPosition(position)
@languageMode = new LanguageMode(this, @buffer.getExtension())

View File

@@ -165,15 +165,21 @@ class RootView extends View
# Public: Opens a given a filepath in Atom.
#
# * path: A file path
# * options
# + initialLine:
# The buffer line number to open to.
#
# Returns the {EditSession} for the file URI.
open: (path, options = {}) ->
changeFocus = options.changeFocus ? true
initialLine = options.initialLine
path = project.relativize(path)
if activePane = @getActivePane()
editSession = activePane.itemForUri(path) ? project.open(path)
editSession = activePane.itemForUri(path) ? project.open(path, {initialLine})
activePane.showItem(editSession)
else
editSession = project.open(path)
editSession = project.open(path, {initialLine})
activePane = new Pane(editSession)
@panes.setRoot(activePane)

View File

@@ -16,8 +16,8 @@ class WindowEventHandler
@subscribe $(window), 'focus', -> $("body").removeClass('is-blurred')
@subscribe $(window), 'blur', -> $("body").addClass('is-blurred')
@subscribe $(window), 'window:open-path', (event, pathToOpen) ->
rootView?.open(pathToOpen) unless fsUtils.isDirectorySync(pathToOpen)
@subscribe $(window), 'window:open-path', (event, {pathToOpen, initialLine}) ->
rootView?.open(pathToOpen, initialLine: initialLine) unless fsUtils.isDirectorySync(pathToOpen)
@subscribe $(window), 'beforeunload', -> rootView?.confirmClose()
@subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen()