WIP: Split panes can be closed with meta-w

Still some issues… view gets screwed up after closing panes in certain layout arrangements.
This commit is contained in:
Nathan Sobo
2012-03-20 12:29:47 -06:00
parent e74f0e66ac
commit 285c04ea62
4 changed files with 56 additions and 6 deletions

View File

@@ -99,6 +99,7 @@ class Editor extends View
@on 'split-right', => @splitRight()
@on 'split-up', => @splitUp()
@on 'split-down', => @splitDown()
@on 'close', => @remove(); false
buildCursorAndSelection: ->
@cursor = new Cursor(this)
@@ -113,6 +114,7 @@ class Editor extends View
false
@hiddenInput.on 'focus', =>
@rootView()?.editorFocused(this)
@isFocused = true
@addClass 'focused'
@@ -157,6 +159,9 @@ class Editor extends View
@setMaxLineLength() if @softWrap
@focus()
rootView: ->
@parents('#root-view').view()
selectTextOnMouseMovement: ->
moveHandler = (e) => @selectToScreenPosition(@screenPositionFromMouseEvent(e))
@on 'mousemove', moveHandler
@@ -440,8 +445,11 @@ class Editor extends View
@parents('#root-view').view().adjustSplitPanes()
remove: (selector, keepData) ->
@unsubscribeFromBuffer() unless keepData
return super if keepData
@unsubscribeFromBuffer()
rootView = @rootView()
super
rootView?.editorRemoved(this)
unsubscribeFromBuffer: ->
@buffer.off ".editor#{@id}"

View File

@@ -15,7 +15,10 @@ class RootView extends View
@div id: 'root-view', =>
@subview 'editor', new Editor
editors: null
initialize: ({url}) ->
@editors = []
@editor.keyEventHandler = window.keymap
@createProject(url)
@@ -36,10 +39,24 @@ class RootView extends View
addPane: (view) ->
@append(view)
editorFocused: (editor) ->
_.remove(@editors, editor)
@editors.push(editor)
editorRemoved: (editor) ->
_.remove(@editors, editor)
@adjustSplitPanes()
if @editors.length
@focusLastActiveEditor()
else
window.close()
focusLastActiveEditor: ->
_.last(@editors).focus()
adjustSplitPanes: (element = @children(':first'))->
if element.hasClass('row')
totalUnits = @horizontalGridUnits(element)
console.log totalUnits
unitsSoFar = 0
for child in element.children()
child = $(child)
@@ -54,7 +71,6 @@ class RootView extends View
else if element.hasClass('column')
totalUnits = @verticalGridUnits(element)
console.log "total vertical", totalUnits
unitsSoFar = 0
for child in element.children()
child = $(child)

View File

@@ -2,7 +2,8 @@ _ = require 'underscore'
_.mixin
remove: (array, element) ->
array.splice(array.indexOf(element), 1)
index = array.indexOf(element)
array.splice(index, 1) if index >= 0
sum: (array) ->
sum = 0