From 229e7e03b2e7ad3f89ddb1e43ee2d237f6c754b7 Mon Sep 17 00:00:00 2001 From: aershov Date: Sun, 21 Dec 2014 20:40:47 +0300 Subject: [PATCH] Respect initialLine and initialColumn options when reopening a file Fix #1743 --- spec/text-editor-spec.coffee | 31 +++++++++++++++++++++++++++++ src/browser/atom-application.coffee | 2 +- src/workspace.coffee | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index b84b3b944..0d8187fed 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -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]]) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 13ab2e7f8..59fb0d24d 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -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 diff --git a/src/workspace.coffee b/src/workspace.coffee index 98630f7c2..54bba00c7 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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}