Respect initialLine and initialColumn options when reopening a file

Fix #1743
This commit is contained in:
aershov
2014-12-21 20:40:47 +03:00
parent 9422a8047a
commit 229e7e03b2
3 changed files with 34 additions and 1 deletions

View File

@@ -78,6 +78,37 @@ describe "TextEditor", ->
expect(editor.getLastCursor().getBufferPosition().row).toEqual 0
expect(editor.getLastCursor().getBufferPosition().column).toEqual 8
describe "when the editor is reopened with an initialLine option", ->
it "positions the cursor on the specified line", ->
editor = null
waitsForPromise ->
atom.workspace.open('sample.less', initialLine: 5).then (o) -> editor = o
waitsForPromise ->
atom.workspace.open('sample.less', initialLine: 4).then (o) -> editor = o
runs ->
buffer = editor.buffer
expect(editor.getLastCursor().getBufferPosition().row).toEqual 4
expect(editor.getLastCursor().getBufferPosition().column).toEqual 0
describe "when the editor is reopened with an initialColumn option", ->
it "positions the cursor on the specified column", ->
editor = null
waitsForPromise ->
atom.workspace.open('sample.less', initialColumn: 8).then (o) -> editor = o
waitsForPromise ->
atom.workspace.open('sample.less', initialColumn: 7).then (o) -> editor = o
runs ->
buffer = editor.buffer
expect(editor.getLastCursor().getBufferPosition().row).toEqual 0
expect(editor.getLastCursor().getBufferPosition().column).toEqual 7
describe ".copy()", ->
it "returns a different edit session with the same initial state", ->
editor.setSelectedBufferRange([[1, 2], [3, 4]])

View File

@@ -359,7 +359,7 @@ class AtomApplication
if existingWindow?
openedWindow = existingWindow
openedWindow.openPath(pathToOpen, initialLine)
openedWindow.openPath(pathToOpen, initialLine, initialColumn)
if openedWindow.isMinimized()
openedWindow.restore()
else

View File

@@ -455,6 +455,8 @@ class Workspace extends Model
@itemOpened(item)
pane.activateItem(item)
pane.activate() if activatePane
if options.initialLine? or options.initialColumn?
item.setCursorBufferPosition([options.initialLine, options.initialColumn])
index = pane.getActiveItemIndex()
@emit "uri-opened"
@emitter.emit 'did-open', {uri, pane, item, index}