mirror of
https://github.com/atom/atom.git
synced 2026-02-10 06:35:00 -05:00
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:
@@ -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()
|
||||
|
||||
@@ -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)')
|
||||
|
||||
@@ -192,3 +192,4 @@ class RootView extends View
|
||||
paths: relativePaths
|
||||
selected: (relativePath) => @open(relativePath)
|
||||
@append @fileFinder
|
||||
@fileFinder.editor.focus()
|
||||
|
||||
Reference in New Issue
Block a user