From 726b546004c68a88b17043a22950aaedaf5a6780 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Jan 2014 13:59:50 -0700 Subject: [PATCH] Handle the 'split' option directly in Workspace::openSingletonSync --- src/pane.coffee | 18 +++++++++++++++++- src/workspace.coffee | 21 ++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/pane.coffee b/src/pane.coffee index 2c1bdfd67..4375ce588 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -1,4 +1,4 @@ -{find, compact, extend} = require 'underscore-plus' +{find, compact, extend, last} = require 'underscore-plus' {dirname} = require 'path' {Model, Sequence} = require 'theorist' Serializable = require 'serializable' @@ -332,3 +332,19 @@ class Pane extends Model newPane.activate() newPane + + # Private: If the parent is a horizontal axis, returns its first child; + # otherwise this pane. + findLeftmostSibling: -> + if @parent.orientation is 'horizontal' + @parent.children[0] + else + this + + # Private: If the parent is a horizontal axis, returns its last child; + # otherwise returns a new pane created by splitting this pane rightward. + findOrCreateRightmostSibling: -> + if @parent.orientation is 'horizontal' + last(@parent.children) + else + @splitRight() diff --git a/src/workspace.coffee b/src/workspace.coffee index 73f2916d9..32d1657f4 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -115,15 +115,22 @@ class Workspace extends Model openSingletonSync: (uri, {changeFocus, initialLine, split}={}) -> changeFocus ?= true uri = atom.project.relativize(uri) - pane = @paneContainer.paneForUri(uri) - if pane - paneItem = pane.itemForUri(uri) - pane.activateItem(paneItem) - pane.activate() if changeFocus - paneItem + if pane = @paneContainer.paneForUri(uri) + editor = pane.itemForUri(uri) else - @openSync(uri, {changeFocus, initialLine, split}) + pane = switch split + when 'left' + @activePane.findLeftmostSibling() + when 'right' + @activePane.findOrCreateRightmostSibling() + else + @activePane + editor = atom.project.openSync(uri, {initialLine}) + + pane.activateItem(editor) + pane.activate() if changeFocus + editor # Public: Reopens the last-closed item uri if it hasn't already been reopened. reopenItemSync: ->