Previously focused editor is re-focused on refresh

The isFocused property has now been added to editor state. When an editor is attached to the dom, it focuses itself automatically if and only if the @isFocused property is true. The @isFocused property gets assigned when the editor is constructed by the root view with its previous state.
This commit is contained in:
Nathan Sobo
2012-04-11 14:58:51 -06:00
parent 144fb29d83
commit 535fba1af8
5 changed files with 15 additions and 26 deletions

View File

@@ -168,7 +168,7 @@ class Editor extends View
@calculateDimensions()
@hiddenInput.width(@charWidth)
@setMaxLineLength() if @softWrap
@focus()
@focus() if @isFocused
rootView: ->
@parents('#root-view').view()
@@ -227,12 +227,14 @@ class Editor extends View
buffer = editorState.buffer ? new Buffer
@editorStatesByBufferId[buffer.id] = editorState
@setBuffer(buffer)
@isFocused = editorState.isFocused
getEditorState: ->
buffer: @buffer
cursorScreenPosition: @getCursorScreenPosition().copy()
scrollTop: @scroller.scrollTop()
scrollLeft: @scroller.scrollLeft()
isFocused: @isFocused
saveEditorStateForCurrentBuffer: ->
@editorStatesByBufferId[@buffer.id] = @getEditorState()

View File

@@ -16,7 +16,6 @@ class FileFinder extends View
initialize: ({@paths, @selected}) ->
requireStylesheet 'file-finder.css'
@maxResults = 10
@previousFocusedElement = $(document.activeElement)
@populatePathList()
@@ -44,10 +43,6 @@ class FileFinder extends View
@selected(filePath) if filePath and @selected
@remove()
remove: ->
super()
@previousFocusedElement.focus()
moveUp: ->
@findSelectedLi()
.filter(':not(:first-child)')

View File

@@ -192,3 +192,4 @@ class RootView extends View
paths: relativePaths
selected: (relativePath) => @open(relativePath)
@append @fileFinder
@fileFinder.editor.focus()