mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Support opening a path into a new split editor
This commit is contained in:
@@ -649,20 +649,20 @@ class Editor extends View
|
||||
|
||||
getFontSize: -> @fontSize
|
||||
|
||||
newSplitEditor: ->
|
||||
new Editor { editSession: @activeEditSession.copy() }
|
||||
newSplitEditor: (editSession) ->
|
||||
new Editor { editSession: editSession ? @activeEditSession.copy() }
|
||||
|
||||
splitLeft: ->
|
||||
@pane()?.splitLeft(@newSplitEditor()).wrappedView
|
||||
splitLeft: (editSession) ->
|
||||
@pane()?.splitLeft(@newSplitEditor(editSession)).wrappedView
|
||||
|
||||
splitRight: ->
|
||||
@pane()?.splitRight(@newSplitEditor()).wrappedView
|
||||
splitRight: (editSession) ->
|
||||
@pane()?.splitRight(@newSplitEditor(editSession)).wrappedView
|
||||
|
||||
splitUp: ->
|
||||
@pane()?.splitUp(@newSplitEditor()).wrappedView
|
||||
splitUp: (editSession) ->
|
||||
@pane()?.splitUp(@newSplitEditor(editSession)).wrappedView
|
||||
|
||||
splitDown: ->
|
||||
@pane()?.splitDown(@newSplitEditor()).wrappedView
|
||||
splitDown: (editSession) ->
|
||||
@pane()?.splitDown(@newSplitEditor(editSession)).wrappedView
|
||||
|
||||
pane: ->
|
||||
@parent('.pane').view()
|
||||
|
||||
@@ -273,3 +273,52 @@ describe 'FuzzyFinder', ->
|
||||
|
||||
runs ->
|
||||
expect(rootView.project.getFilePaths).toHaveBeenCalled()
|
||||
|
||||
describe "opening a path into a split", ->
|
||||
beforeEach ->
|
||||
rootView.attachToDom()
|
||||
|
||||
describe "when an editor is active", ->
|
||||
it "opens the path by splitting the active editor left", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
spyOn(editor, "splitLeft").andCallThrough()
|
||||
expect(rootView.find('.editor').length).toBe 1
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
finder.miniEditor.trigger 'editor:split-left'
|
||||
expect(rootView.find('.editor').length).toBe 2
|
||||
expect(editor.splitLeft).toHaveBeenCalled()
|
||||
expect(rootView.getActiveEditor()).not.toBe editor
|
||||
expect(rootView.getActiveEditor().getPath()).toBe editor.getPath()
|
||||
|
||||
it "opens the path by splitting the active editor right", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
spyOn(editor, "splitRight").andCallThrough()
|
||||
expect(rootView.find('.editor').length).toBe 1
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
finder.miniEditor.trigger 'editor:split-right'
|
||||
expect(rootView.find('.editor').length).toBe 2
|
||||
expect(editor.splitRight).toHaveBeenCalled()
|
||||
expect(rootView.getActiveEditor()).not.toBe editor
|
||||
expect(rootView.getActiveEditor().getPath()).toBe editor.getPath()
|
||||
|
||||
it "opens the path by splitting the active editor down", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
spyOn(editor, "splitDown").andCallThrough()
|
||||
expect(rootView.find('.editor').length).toBe 1
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
finder.miniEditor.trigger 'editor:split-down'
|
||||
expect(rootView.find('.editor').length).toBe 2
|
||||
expect(editor.splitDown).toHaveBeenCalled()
|
||||
expect(rootView.getActiveEditor()).not.toBe editor
|
||||
expect(rootView.getActiveEditor().getPath()).toBe editor.getPath()
|
||||
|
||||
it "opens the path by splitting the active editor up", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
spyOn(editor, "splitUp").andCallThrough()
|
||||
expect(rootView.find('.editor').length).toBe 1
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
finder.miniEditor.trigger 'editor:split-up'
|
||||
expect(rootView.find('.editor').length).toBe 2
|
||||
expect(editor.splitUp).toHaveBeenCalled()
|
||||
expect(rootView.getActiveEditor()).not.toBe editor
|
||||
expect(rootView.getActiveEditor().getPath()).toBe editor.getPath()
|
||||
|
||||
@@ -24,6 +24,15 @@ class FuzzyFinder extends SelectList
|
||||
@observeConfig 'fuzzy-finder.ignoredNames', (ignoredNames) =>
|
||||
@projectPaths = null
|
||||
|
||||
@miniEditor.command 'editor:split-left', =>
|
||||
@splitOpenPath (editor, session) -> editor.splitLeft(session)
|
||||
@miniEditor.command 'editor:split-right', =>
|
||||
@splitOpenPath (editor, session) -> editor.splitRight(session)
|
||||
@miniEditor.command 'editor:split-down', =>
|
||||
@splitOpenPath (editor, session) -> editor.splitDown(session)
|
||||
@miniEditor.command 'editor:split-up', =>
|
||||
@splitOpenPath (editor, session) -> editor.splitUp(session)
|
||||
|
||||
itemForElement: (path) ->
|
||||
$$ ->
|
||||
@li =>
|
||||
@@ -40,10 +49,23 @@ class FuzzyFinder extends SelectList
|
||||
if folder = fs.directory(path)
|
||||
@span "- #{folder}/", class: 'directory'
|
||||
|
||||
openPath: (path) ->
|
||||
@rootView.open(path, {@allowActiveEditorChange}) if path
|
||||
|
||||
splitOpenPath: (fn) ->
|
||||
path = @getSelectedElement()
|
||||
return unless path
|
||||
|
||||
editor = @rootView.getActiveEditor()
|
||||
if editor
|
||||
fn(editor, @rootView.project.buildEditSessionForPath(path))
|
||||
else
|
||||
@openPath(path)
|
||||
|
||||
confirmed : (path) ->
|
||||
return unless path.length
|
||||
@cancel()
|
||||
@rootView.open(path, {@allowActiveEditorChange})
|
||||
@openPath(path)
|
||||
|
||||
cancelled: ->
|
||||
@miniEditor.setText('')
|
||||
|
||||
Reference in New Issue
Block a user