mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
RootView.open takes an 'allowActiveEditorChange' option
When the 'allowActiveEditorChange' option is true, RootView will try to activate an existing edit session for the given path on *any* editor, and switch focus there. This will be used by the fuzzy-finder for the meta-b option, which should open the chosen buffer on the editor that contains it, even if it isn't currently active.
This commit is contained in:
@@ -389,6 +389,13 @@ class Editor extends View
|
||||
|
||||
@renderWhenAttached()
|
||||
|
||||
activateEditSessionForPath: (path) ->
|
||||
for editSession, index in @editSessions
|
||||
if editSession.buffer.getPath() == path
|
||||
@setActiveEditSessionIndex(index)
|
||||
return true
|
||||
false
|
||||
|
||||
getOpenBufferPaths: ->
|
||||
editSession.buffer.path for editSession in @editSessions when editSession.buffer.path?
|
||||
|
||||
|
||||
@@ -91,13 +91,12 @@ class RootView extends View
|
||||
extension.deactivate?() for name, extension of @extensions
|
||||
@remove()
|
||||
|
||||
open: (path, changeFocus=true) ->
|
||||
editSession = @project.open(path)
|
||||
open: (path, options = {}) ->
|
||||
changeFocus = options.changeFocus ? true
|
||||
allowActiveEditorChange = options.allowActiveEditorChange ? false
|
||||
|
||||
if @activeEditor()
|
||||
@activeEditor().edit(editSession)
|
||||
else
|
||||
editor = new Editor(editSession: editSession)
|
||||
unless @openInExistingEditor(path, allowActiveEditorChange)
|
||||
editor = new Editor(editSession: @project.open(path))
|
||||
pane = new Pane(editor)
|
||||
@panes.append(pane)
|
||||
if changeFocus
|
||||
@@ -105,6 +104,24 @@ class RootView extends View
|
||||
else
|
||||
@makeEditorActive(editor)
|
||||
|
||||
openInExistingEditor: (path, allowActiveEditorChange) ->
|
||||
if activeEditor = @activeEditor()
|
||||
path = @project.resolve(path) if path
|
||||
|
||||
if activeEditor.activateEditSessionForPath(path)
|
||||
return true
|
||||
|
||||
if allowActiveEditorChange
|
||||
for editor in @editors()
|
||||
if editor.activateEditSessionForPath(path)
|
||||
editor.focus()
|
||||
return true
|
||||
|
||||
activeEditor.edit(@project.open(path))
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
editorFocused: (editor) ->
|
||||
@makeEditorActive(editor) if @panes.containsElement(editor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user