mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Get fuzzy-finder specs passing w/ new panes
Could still probably use some cleanup and I'm not sure everything is working correctly with regards to focus.
This commit is contained in:
committed by
probablycorey
parent
279ebc0958
commit
a2ddd10d31
@@ -89,6 +89,7 @@ class RootView extends View
|
||||
@remove()
|
||||
|
||||
open: (path, options = {}) ->
|
||||
path = project.resolve(path) if path?
|
||||
if activePane = @getActivePane()
|
||||
if editSession = activePane.itemForPath(path)
|
||||
activePane.showItem(editSession)
|
||||
|
||||
@@ -22,19 +22,18 @@ class FuzzyFinderView extends SelectList
|
||||
|
||||
@subscribe $(window), 'focus', => @reloadProjectPaths = true
|
||||
@observeConfig 'fuzzy-finder.ignoredNames', => @reloadProjectPaths = true
|
||||
rootView.eachEditor (editor) ->
|
||||
editor.activeEditSession.lastOpened = (new Date) - 1
|
||||
editor.on 'editor:active-edit-session-changed', (e, editSession, index) ->
|
||||
editSession.lastOpened = (new Date) - 1
|
||||
rootView.eachPane (pane) ->
|
||||
pane.activeItem.lastOpened = (new Date) - 1
|
||||
pane.on 'pane:active-item-changed', (e, item) -> item.lastOpened = (new Date) - 1
|
||||
|
||||
@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)
|
||||
@miniEditor.command 'pane:split-left', =>
|
||||
@splitOpenPath (pane, session) -> pane.splitLeft(session)
|
||||
@miniEditor.command 'pane:split-right', =>
|
||||
@splitOpenPath (pane, session) -> pane.splitRight(session)
|
||||
@miniEditor.command 'pane:split-down', =>
|
||||
@splitOpenPath (pane, session) -> pane.splitDown(session)
|
||||
@miniEditor.command 'pane:split-up', =>
|
||||
@splitOpenPath (pane, session) -> pane.splitUp(session)
|
||||
|
||||
itemForElement: (path) ->
|
||||
$$ ->
|
||||
@@ -70,10 +69,8 @@ class FuzzyFinderView extends SelectList
|
||||
splitOpenPath: (fn) ->
|
||||
path = @getSelectedElement()
|
||||
return unless path
|
||||
|
||||
editor = rootView.getActiveEditor()
|
||||
if editor
|
||||
fn(editor, project.buildEditSession(path))
|
||||
if pane = rootView.getActivePane()
|
||||
fn(pane, project.buildEditSession(path))
|
||||
else
|
||||
@openPath(path)
|
||||
|
||||
@@ -118,7 +115,7 @@ class FuzzyFinderView extends SelectList
|
||||
else
|
||||
return unless project.getPath()?
|
||||
@allowActiveEditorChange = false
|
||||
editor = rootView.getActiveEditor()
|
||||
editor = rootView.getActiveView()
|
||||
currentWord = editor.getWordUnderCursor(wordRegex: @filenameRegex)
|
||||
|
||||
if currentWord.length == 0
|
||||
@@ -177,7 +174,7 @@ class FuzzyFinderView extends SelectList
|
||||
editSession.getPath()?
|
||||
|
||||
editSessions = _.sortBy editSessions, (editSession) =>
|
||||
if editSession is rootView.getActiveEditSession()
|
||||
if editSession is rootView.getActivePaneItem()
|
||||
0
|
||||
else
|
||||
-(editSession.lastOpened or 1)
|
||||
|
||||
@@ -21,8 +21,8 @@ describe 'FuzzyFinder', ->
|
||||
it "shows the FuzzyFinder or hides it and returns focus to the active editor if it already showing", ->
|
||||
rootView.attachToDom()
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
rootView.find('.editor').trigger 'editor:split-right'
|
||||
[editor1, editor2] = rootView.find('.editor').map -> $(this).view()
|
||||
rootView.getActiveView().splitRight()
|
||||
[editor1, editor2] = rootView.getEditors()
|
||||
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
rootView.trigger 'fuzzy-finder:toggle-file-finder'
|
||||
@@ -72,9 +72,9 @@ describe 'FuzzyFinder', ->
|
||||
describe "when a path selection is confirmed", ->
|
||||
it "opens the file associated with that path in the editor", ->
|
||||
rootView.attachToDom()
|
||||
editor1 = rootView.getActiveEditor()
|
||||
editor1 = rootView.getActiveView()
|
||||
editor2 = editor1.splitRight()
|
||||
expect(rootView.getActiveEditor()).toBe editor2
|
||||
expect(rootView.getActiveView()).toBe editor2
|
||||
rootView.trigger 'fuzzy-finder:toggle-file-finder'
|
||||
|
||||
finderView.confirmed('dir/a')
|
||||
@@ -88,26 +88,26 @@ describe 'FuzzyFinder', ->
|
||||
describe "when the selected path isn't a file that exists", ->
|
||||
it "leaves the the tree view open, doesn't open the path in the editor, and displays an error", ->
|
||||
rootView.attachToDom()
|
||||
path = rootView.getActiveEditor().getPath()
|
||||
path = rootView.getActiveView().getPath()
|
||||
rootView.trigger 'fuzzy-finder:toggle-file-finder'
|
||||
finderView.confirmed('dir/this/is/not/a/file.txt')
|
||||
expect(finderView.hasParent()).toBeTruthy()
|
||||
expect(rootView.getActiveEditor().getPath()).toBe path
|
||||
expect(rootView.getActiveView().getPath()).toBe path
|
||||
expect(finderView.find('.error').text().length).toBeGreaterThan 0
|
||||
advanceClock(2000)
|
||||
expect(finderView.find('.error').text().length).toBe 0
|
||||
|
||||
describe "buffer-finder behavior", ->
|
||||
describe "toggling", ->
|
||||
describe "when the active editor contains edit sessions for buffers with paths", ->
|
||||
describe "when there are pane items with paths", ->
|
||||
beforeEach ->
|
||||
rootView.open('sample.txt')
|
||||
|
||||
it "shows the FuzzyFinder or hides it, returning focus to the active editor if", ->
|
||||
it "shows the FuzzyFinder if it isn't showing, or hides it and returns focus to the active editor", ->
|
||||
rootView.attachToDom()
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
rootView.find('.editor').trigger 'editor:split-right'
|
||||
[editor1, editor2] = rootView.find('.editor').map -> $(this).view()
|
||||
rootView.getActiveView().splitRight()
|
||||
[editor1, editor2] = rootView.getEditors()
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(rootView.find('.fuzzy-finder')).toExist()
|
||||
@@ -122,26 +122,17 @@ describe 'FuzzyFinder', ->
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(finderView.miniEditor.getText()).toBe ''
|
||||
|
||||
it "lists the paths of the current open buffers by most recently modified", ->
|
||||
it "lists the paths of the current items, sorted by most recently opened but with the current item last", ->
|
||||
rootView.attachToDom()
|
||||
rootView.open 'sample-with-tabs.coffee'
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
children = finderView.list.children('li')
|
||||
expect(children.get(0).outerText).toBe "sample.txt"
|
||||
expect(children.get(1).outerText).toBe "sample.js"
|
||||
expect(children.get(2).outerText).toBe "sample-with-tabs.coffee"
|
||||
expect(_.pluck(finderView.list.children('li'), 'outerText')).toEqual ['sample.txt', 'sample.js', 'sample-with-tabs.coffee']
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
||||
rootView.open 'sample.txt'
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
children = finderView.list.children('li')
|
||||
expect(children.get(0).outerText).toBe "sample-with-tabs.coffee"
|
||||
expect(children.get(1).outerText).toBe "sample.js"
|
||||
expect(children.get(2).outerText).toBe "sample.txt"
|
||||
|
||||
expect(finderView.list.children('li').length).toBe 3
|
||||
expect(finderView.list.find("li:contains(sample.js)")).toExist()
|
||||
expect(finderView.list.find("li:contains(sample.txt)")).toExist()
|
||||
expect(finderView.list.find("li:contains(sample-with-tabs.coffee)")).toExist()
|
||||
expect(_.pluck(finderView.list.children('li'), 'outerText')).toEqual ['sample-with-tabs.coffee', 'sample.js', 'sample.txt']
|
||||
expect(finderView.list.children().first()).toHaveClass 'selected'
|
||||
|
||||
it "serializes the list of paths and their last opened time", ->
|
||||
@@ -156,24 +147,21 @@ describe 'FuzzyFinder', ->
|
||||
states = _.sortBy states, (path, time) -> -time
|
||||
|
||||
paths = [ 'sample-with-tabs.coffee', 'sample.txt', 'sample.js' ]
|
||||
|
||||
for [time, path] in states
|
||||
expect(_.last path.split '/').toBe paths.shift()
|
||||
expect(time).toBeGreaterThan 50000
|
||||
|
||||
describe "when the active editor only contains edit sessions for anonymous buffers", ->
|
||||
describe "when there are only panes with anonymous items", ->
|
||||
it "does not open", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.edit(project.buildEditSession())
|
||||
editor.loadPreviousEditSession()
|
||||
editor.destroyActiveEditSession()
|
||||
expect(editor.getOpenBufferPaths().length).toBe 0
|
||||
rootView.getActivePane().remove()
|
||||
rootView.open()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
|
||||
describe "when there is no active editor", ->
|
||||
describe "when there are no pane items", ->
|
||||
it "does not open", ->
|
||||
rootView.getActiveEditor().destroyActiveEditSession()
|
||||
expect(rootView.getActiveEditor()).toBeUndefined()
|
||||
rootView.getActivePane().remove()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
|
||||
@@ -182,15 +170,15 @@ describe 'FuzzyFinder', ->
|
||||
|
||||
beforeEach ->
|
||||
rootView.attachToDom()
|
||||
editor1 = rootView.getActiveEditor()
|
||||
editor1 = rootView.getActiveView()
|
||||
editor2 = editor1.splitRight()
|
||||
expect(rootView.getActiveEditor()).toBe editor2
|
||||
expect(rootView.getActiveView()).toBe editor2
|
||||
rootView.open('sample.txt')
|
||||
editor2.loadPreviousEditSession()
|
||||
editor2.trigger 'pane:show-previous-item'
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
||||
describe "when there is an edit session for the confirmed path in the active editor", ->
|
||||
it "switches the active editor to the edit session for the selected path", ->
|
||||
describe "when the active pane has an item for the selected path", ->
|
||||
it "switches to the item for the selected path", ->
|
||||
expectedPath = fixturesProject.resolve('sample.txt')
|
||||
finderView.confirmed('sample.txt')
|
||||
|
||||
@@ -199,21 +187,20 @@ describe 'FuzzyFinder', ->
|
||||
expect(editor2.getPath()).toBe expectedPath
|
||||
expect(editor2.isFocused).toBeTruthy()
|
||||
|
||||
describe "when there is NO edit session for the confirmed path on the active editor, but there is one on another editor", ->
|
||||
it "focuses the editor that contains an edit session for the selected path", ->
|
||||
describe "when the active pane does not have an item for the selected path", ->
|
||||
it "adds a new item to the active pane for the selcted path", ->
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
editor1.focus()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
||||
expect(rootView.getActiveEditor()).toBe editor1
|
||||
expect(rootView.getActiveView()).toBe editor1
|
||||
|
||||
expectedPath = fixturesProject.resolve('sample.txt')
|
||||
finderView.confirmed('sample.txt')
|
||||
|
||||
expect(finderView.hasParent()).toBeFalsy()
|
||||
expect(editor1.getPath()).not.toBe expectedPath
|
||||
expect(editor2.getPath()).toBe expectedPath
|
||||
expect(editor2.isFocused).toBeTruthy()
|
||||
expect(editor1.getPath()).toBe expectedPath
|
||||
expect(editor1.isFocused).toBeTruthy()
|
||||
|
||||
describe "git-status-finder behavior", ->
|
||||
[originalText, originalPath, newPath] = []
|
||||
@@ -248,7 +235,7 @@ describe 'FuzzyFinder', ->
|
||||
describe "when an editor is open", ->
|
||||
it "detaches the finder and focuses the previously focused element", ->
|
||||
rootView.attachToDom()
|
||||
activeEditor = rootView.getActiveEditor()
|
||||
activeEditor = rootView.getActiveView()
|
||||
activeEditor.focus()
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-file-finder'
|
||||
@@ -265,7 +252,7 @@ describe 'FuzzyFinder', ->
|
||||
describe "when no editors are open", ->
|
||||
it "detaches the finder and focuses the previously focused element", ->
|
||||
rootView.attachToDom()
|
||||
rootView.getActiveEditor().destroyActiveEditSession()
|
||||
rootView.getActivePane().remove()
|
||||
|
||||
inputView = $$ -> @input()
|
||||
rootView.append(inputView)
|
||||
@@ -351,7 +338,7 @@ describe 'FuzzyFinder', ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
editor = rootView.getActiveEditor()
|
||||
editor = rootView.getActiveView()
|
||||
rootView.attachToDom()
|
||||
|
||||
it "opens the fuzzy finder window when there are multiple matches", ->
|
||||
@@ -405,59 +392,63 @@ describe 'FuzzyFinder', ->
|
||||
expect(finderView.find('.error').text().length).toBeGreaterThan 0
|
||||
|
||||
describe "opening a path into a split", ->
|
||||
beforeEach ->
|
||||
rootView.attachToDom()
|
||||
it "opens the path by splitting the active editor left", ->
|
||||
expect(rootView.getPanes().length).toBe 1
|
||||
pane = rootView.getActivePane()
|
||||
spyOn(pane, "splitLeft").andCallThrough()
|
||||
|
||||
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'
|
||||
finderView.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()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
path = finderView.getSelectedElement()
|
||||
finderView.miniEditor.trigger 'pane:split-left'
|
||||
|
||||
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'
|
||||
finderView.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()
|
||||
expect(rootView.getPanes().length).toBe 2
|
||||
expect(pane.splitLeft).toHaveBeenCalled()
|
||||
expect(rootView.getActiveView().getPath()).toBe project.resolve(path)
|
||||
|
||||
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'
|
||||
finderView.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 right", ->
|
||||
expect(rootView.getPanes().length).toBe 1
|
||||
pane = rootView.getActivePane()
|
||||
spyOn(pane, "splitRight").andCallThrough()
|
||||
|
||||
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'
|
||||
finderView.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()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
path = finderView.getSelectedElement()
|
||||
finderView.miniEditor.trigger 'pane:split-right'
|
||||
|
||||
expect(rootView.getPanes().length).toBe 2
|
||||
expect(pane.splitRight).toHaveBeenCalled()
|
||||
expect(rootView.getActiveView().getPath()).toBe project.resolve(path)
|
||||
|
||||
it "opens the path by splitting the active editor up", ->
|
||||
expect(rootView.getPanes().length).toBe 1
|
||||
pane = rootView.getActivePane()
|
||||
spyOn(pane, "splitUp").andCallThrough()
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
path = finderView.getSelectedElement()
|
||||
finderView.miniEditor.trigger 'pane:split-up'
|
||||
|
||||
expect(rootView.getPanes().length).toBe 2
|
||||
expect(pane.splitUp).toHaveBeenCalled()
|
||||
expect(rootView.getActiveView().getPath()).toBe project.resolve(path)
|
||||
|
||||
it "opens the path by splitting the active editor down", ->
|
||||
expect(rootView.getPanes().length).toBe 1
|
||||
pane = rootView.getActivePane()
|
||||
spyOn(pane, "splitDown").andCallThrough()
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
path = finderView.getSelectedElement()
|
||||
finderView.miniEditor.trigger 'pane:split-down'
|
||||
|
||||
expect(rootView.getPanes().length).toBe 2
|
||||
expect(pane.splitDown).toHaveBeenCalled()
|
||||
expect(rootView.getActiveView().getPath()).toBe project.resolve(path)
|
||||
|
||||
describe "git status decorations", ->
|
||||
[originalText, originalPath, editor, newPath] = []
|
||||
|
||||
beforeEach ->
|
||||
editor = rootView.getActiveEditor()
|
||||
editor = rootView.getActiveView()
|
||||
originalText = editor.getText()
|
||||
originalPath = editor.getPath()
|
||||
newPath = project.resolve('newsample.js')
|
||||
|
||||
Reference in New Issue
Block a user