mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add initialColumn options to Workspace::open
This options works similarly to the existing initialLine option
This commit is contained in:
@@ -43,6 +43,19 @@ describe "Editor", ->
|
||||
runs ->
|
||||
buffer = editor.buffer
|
||||
expect(editor.getCursor().getBufferPosition().row).toEqual 5
|
||||
expect(editor.getCursor().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 ->
|
||||
buffer = editor.buffer
|
||||
expect(editor.getCursor().getBufferPosition().row).toEqual 0
|
||||
expect(editor.getCursor().getBufferPosition().column).toEqual 8
|
||||
|
||||
describe ".copy()", ->
|
||||
it "returns a different edit session with the same initial state", ->
|
||||
|
||||
@@ -152,7 +152,7 @@ class Editor extends Model
|
||||
@delegatesProperties '$lineHeight', '$defaultCharWidth', '$height', '$width',
|
||||
'$scrollTop', '$scrollLeft', 'manageScrollPosition', toProperty: 'displayBuffer'
|
||||
|
||||
constructor: ({@softTabs, initialLine, tabLength, softWrap, @displayBuffer, buffer, registerEditor, suppressCursorCreation}) ->
|
||||
constructor: ({@softTabs, initialLine, initialColumn, tabLength, softWrap, @displayBuffer, buffer, registerEditor, suppressCursorCreation}) ->
|
||||
super
|
||||
|
||||
@cursors = []
|
||||
@@ -170,11 +170,9 @@ class Editor extends Model
|
||||
@subscribeToDisplayBuffer()
|
||||
|
||||
if @getCursors().length is 0 and not suppressCursorCreation
|
||||
if initialLine
|
||||
position = [initialLine, 0]
|
||||
else
|
||||
position = [0, 0]
|
||||
@addCursorAtBufferPosition(position)
|
||||
initialLine = Math.max(parseInt(initialLine) or 0, 0)
|
||||
initialColumn = Math.max(parseInt(initialColumn) or 0, 0)
|
||||
@addCursorAtBufferPosition([initialLine, initialColumn])
|
||||
|
||||
@languageMode = new LanguageMode(this)
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ class Workspace extends Model
|
||||
# options - An optional options {Object}
|
||||
# :initialLine - A {Number} indicating which row to move the cursor to
|
||||
# initially. Defaults to `0`.
|
||||
# :initialColumn - A {Number} indicating which column to move the cursor to
|
||||
# initially. Defaults to `0`.
|
||||
# :split - Either 'left' or 'right'. If 'left', the item will be opened in
|
||||
# leftmost pane of the current active pane's row. If 'right', the
|
||||
# item will be opened in the rightmost pane of the current active
|
||||
@@ -124,12 +126,14 @@ class Workspace extends Model
|
||||
# options - An optional options {Object}
|
||||
# :initialLine - A {Number} indicating which row to move the cursor to
|
||||
# initially. Defaults to `0`.
|
||||
# :initialColumn - A {Number} indicating which column to move the cursor to
|
||||
# initially. Defaults to `0`.
|
||||
# :activatePane - A {Boolean} indicating whether to call {Pane::activate} on
|
||||
# the containing pane. Defaults to `true`.
|
||||
openSync: (uri='', options={}) ->
|
||||
deprecate("Don't use the `changeFocus` option") if options.changeFocus?
|
||||
|
||||
{initialLine} = options
|
||||
{initialLine, initialColumn} = options
|
||||
# TODO: Remove deprecated changeFocus option
|
||||
activatePane = options.activatePane ? options.changeFocus ? true
|
||||
uri = atom.project.resolve(uri)
|
||||
@@ -137,7 +141,7 @@ class Workspace extends Model
|
||||
item = @activePane.itemForUri(uri)
|
||||
if uri
|
||||
item ?= opener(uri, options) for opener in @getOpeners() when !item
|
||||
item ?= atom.project.openSync(uri, {initialLine})
|
||||
item ?= atom.project.openSync(uri, {initialLine, initialColumn})
|
||||
|
||||
@activePane.activateItem(item)
|
||||
@itemOpened(item)
|
||||
|
||||
Reference in New Issue
Block a user