Allow Infinity for initialLine/Column; move specs to workspace

The initialLine and initialColumn behavior belongs on workspace.
This commit is contained in:
Nathan Sobo 2015-08-10 11:32:38 -06:00
parent 69da157ecb
commit f9a576b0ce
3 changed files with 20 additions and 76 deletions

View File

@ -85,80 +85,6 @@ describe "TextEditor", ->
expect(editor.tokenizedLineForScreenRow(0).tokens.length).toBe 1
expect(editor.tokenizedLineForScreenRow(1).tokens.length).toBe 2 # sof tab
describe "when the editor is constructed 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
runs ->
expect(editor.getLastCursor().getBufferPosition().row).toEqual 5
expect(editor.getLastCursor().getBufferPosition().column).toEqual 0
describe "when the editor is constructed 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
runs ->
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
it "ignores non-numeric initialLine and initialColumn options", ->
[editor1, editor2, editor3] = []
waitsForPromise ->
atom.workspace.open('sample.less', initialColumn: 8, initialLine: NaN).then (o) -> editor1 = o
runs ->
expect(editor1.getLastCursor().getBufferPosition().row).toEqual 0
expect(editor1.getLastCursor().getBufferPosition().column).toEqual 8
waitsForPromise ->
atom.workspace.open('sample.less', initialColumn: NaN, initialLine: 3).then (o) -> editor2 = o
runs ->
expect(editor2.getLastCursor().getBufferPosition().row).toEqual 3
expect(editor2.getLastCursor().getBufferPosition().column).toEqual 0
waitsForPromise ->
atom.workspace.open('sample.less', initialColumn: NaN, initialLine: NaN).then (o) -> editor3 = o
runs ->
expect(editor3.getLastCursor().getBufferPosition().row).toEqual 3
expect(editor3.getLastCursor().getBufferPosition().column).toEqual 0
describe ".copy()", ->
it "returns a different edit session with the same initial state", ->
editor.setSelectedBufferRange([[1, 2], [3, 4]])

View File

@ -245,6 +245,24 @@ describe "Workspace", ->
runs ->
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 0]
waitsForPromise ->
workspace.open('a', initialLine: NaN, initialColumn: 4)
runs ->
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 4]
waitsForPromise ->
workspace.open('a', initialLine: 2, initialColumn: NaN)
runs ->
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [2, 0]
waitsForPromise ->
workspace.open('a', initialLine: Infinity, initialColumn: Infinity)
runs ->
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [2, 11]
describe "when the file is over 2MB", ->
it "opens the editor with largeFileMode: true", ->
spyOn(fs, 'getSizeSync').andReturn 2 * 1048577 # 2MB

View File

@ -468,9 +468,9 @@ class Workspace extends Model
pane.activate() if activatePane
initialLine = initialColumn = 0
if Number.isFinite(options.initialLine)
unless Number.isNaN(options.initialLine)
initialLine = options.initialLine
if Number.isFinite(options.initialColumn)
unless Number.isNaN(options.initialColumn)
initialColumn = options.initialColumn
if initialLine >= 0 or initialColumn >= 0
item.setCursorBufferPosition?([initialLine, initialColumn])