Editors in #panes are always contained by .pane wrappers

This prepares us to refactor the split view and editor state code into Column, Row, and Pane objects.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-11 18:37:22 -06:00
parent 8a4b5b13bb
commit 416a15e3af
6 changed files with 79 additions and 56 deletions

View File

@@ -506,15 +506,17 @@ class Editor extends View
split: (axis, side) ->
return unless rootView = @rootView()
editor = new Editor(@getEditorState())
rootView.addPane(editor, this, axis, side)
rootView.addPane(editor, this.parent(), axis, side)
remove: (selector, keepData) ->
return super if keepData
@unsubscribeFromBuffer()
rootView = @rootView()
parent = @parent()
pane = @parent('.pane')
paneParent = pane.parent()
super
parent.remove() if parent.is('.row:empty, .column:empty')
pane.remove()
paneParent.remove() if paneParent.is('.row:empty, .column:empty')
rootView?.editorRemoved(this)
unsubscribeFromBuffer: ->

5
src/app/pane.coffee Normal file
View File

@@ -0,0 +1,5 @@
module.exports =
class Pane
@content: (view) ->
@div class: 'pane', =>
@subview 'view', view

View File

@@ -10,6 +10,7 @@ FileFinder = require 'file-finder'
Project = require 'project'
VimMode = require 'vim-mode'
CommandPanel = require 'command-panel'
Pane = require 'pane'
module.exports =
class RootView extends View
@@ -79,11 +80,15 @@ class RootView extends View
if editor.length
editor.view()
else
new Editor().appendTo(@panes).focus()
editor = new Editor
pane = new Pane(editor)
@panes.append(pane)
editor.focus()
editor
getWindowState: (element = @panes.children(':eq(0)')) ->
if element.hasClass('editor')
['editor', element.view().getEditorState()]
if element.hasClass('pane')
['editor', element.view().content.getEditorState()]
else if element.hasClass('row')
['row'].concat element.children().toArray().map (elt) =>
@getWindowState($(elt))
@@ -100,8 +105,8 @@ class RootView extends View
switch windowState.shift()
when 'editor'
editor = new Editor(windowState[0])
parent.append(editor)
editor = new Editor(windowState...)
parent.append(new Pane(editor))
when 'row'
row = $$ -> @div class: 'row'
parent.append row
@@ -119,7 +124,8 @@ class RootView extends View
unless sibling.parent().hasClass(axis)
container = $$ -> @div class: axis
container.insertBefore(sibling).append(sibling.detach())
sibling[side](view)
pane = new Pane(view)
sibling[side](pane)
@adjustSplitPanes()
view