Merge pull request #4729 from alexandershov/master

Respect initialLine and initialColumn options when reopening a file
This commit is contained in:
Kevin Sawicki
2014-12-22 16:07:11 -08:00
3 changed files with 31 additions and 3 deletions

View File

@@ -62,7 +62,6 @@ describe "TextEditor", ->
atom.workspace.open('sample.less', initialLine: 5).then (o) -> editor = o
runs ->
buffer = editor.buffer
expect(editor.getLastCursor().getBufferPosition().row).toEqual 5
expect(editor.getLastCursor().getBufferPosition().column).toEqual 0
@@ -74,10 +73,37 @@ describe "TextEditor", ->
atom.workspace.open('sample.less', initialColumn: 8).then (o) -> editor = o
runs ->
buffer = editor.buffer
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 ->
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 ->
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}