mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
When focus changes to a different editor, highlight its open file in the TreeView
Trigger 'active-editor-path-change' event whenever active editor changes or the path of the active editor changes. Rename 'buffer-path-change' to 'editor-path-change' to emphasize that it's the path open in an *editor* that's changing.
This commit is contained in:
@@ -2110,24 +2110,24 @@ describe "Editor", ->
|
||||
expect(editor.lines.find('.line:eq(14)').text()).toBe 'B'
|
||||
expect(editor.lines.find('.line:eq(15)')).not.toExist()
|
||||
|
||||
describe "path-change event", ->
|
||||
describe "editor-path-change event", ->
|
||||
it "emits event when buffer's path is changed", ->
|
||||
editor = new Editor
|
||||
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on 'buffer-path-change', eventHandler
|
||||
editor.on 'editor-path-change', eventHandler
|
||||
editor.buffer.setPath("moo.text")
|
||||
|
||||
it "emits event when editor receives a new buffer", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on 'buffer-path-change', eventHandler
|
||||
editor.on 'editor-path-change', eventHandler
|
||||
editor.setBuffer(new Buffer("something.txt"))
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
it "stops listening to events on previously set buffers", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
oldBuffer = editor.buffer
|
||||
editor.on 'buffer-path-change', eventHandler
|
||||
editor.on 'editor-path-change', eventHandler
|
||||
|
||||
editor.setBuffer(new Buffer("something.txt"))
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
@@ -126,7 +126,7 @@ describe "RootView", ->
|
||||
expect(rootView.activeEditor().isFocused).toBeTruthy()
|
||||
|
||||
describe "panes", ->
|
||||
pane1 = null
|
||||
[pane1, newPaneContent] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView.attachToDom()
|
||||
@@ -134,13 +134,16 @@ describe "RootView", ->
|
||||
rootView.height(600)
|
||||
pane1 = rootView.find('.pane').view()
|
||||
pane1.attr('id', 'pane-1')
|
||||
newPaneContent = $("<div>New pane content</div>")
|
||||
spyOn(newPaneContent, 'focus')
|
||||
|
||||
describe "vertical splits", ->
|
||||
describe "when .splitRight(view) is called on a pane", ->
|
||||
it "places a new pane to the right of the current pane in a .row div", ->
|
||||
expect(rootView.panes.find('.row')).not.toExist()
|
||||
|
||||
pane2 = pane1.splitRight("<div>New pane content</div>")
|
||||
pane2 = pane1.splitRight(newPaneContent)
|
||||
expect(newPaneContent.focus).toHaveBeenCalled()
|
||||
|
||||
expect(rootView.panes.find('.row')).toExist()
|
||||
expect(rootView.panes.find('.row .pane').length).toBe 2
|
||||
@@ -164,7 +167,8 @@ describe "RootView", ->
|
||||
it "places a new pane to the left of the current pane in a .row div", ->
|
||||
expect(rootView.find('.row')).not.toExist()
|
||||
|
||||
pane2 = pane1.splitLeft("<div>New pane content</div>")
|
||||
pane2 = pane1.splitLeft(newPaneContent)
|
||||
expect(newPaneContent.focus).toHaveBeenCalled()
|
||||
|
||||
expect(rootView.find('.row')).toExist()
|
||||
expect(rootView.find('.row .pane').length).toBe 2
|
||||
@@ -190,7 +194,8 @@ describe "RootView", ->
|
||||
it "places a new pane above the current pane in a .column div", ->
|
||||
expect(rootView.find('.column')).not.toExist()
|
||||
|
||||
pane2 = pane1.splitUp("<div>New pane content</div>")
|
||||
pane2 = pane1.splitUp(newPaneContent)
|
||||
expect(newPaneContent.focus).toHaveBeenCalled()
|
||||
|
||||
expect(rootView.find('.column')).toExist()
|
||||
expect(rootView.find('.column .pane').length).toBe 2
|
||||
@@ -215,7 +220,8 @@ describe "RootView", ->
|
||||
it "places a new pane below the current pane in a .column div", ->
|
||||
expect(rootView.find('.column')).not.toExist()
|
||||
|
||||
pane2 = pane1.splitDown("<div>New pane content</div>")
|
||||
pane2 = pane1.splitDown(newPaneContent)
|
||||
expect(newPaneContent.focus).toHaveBeenCalled()
|
||||
|
||||
expect(rootView.find('.column')).toExist()
|
||||
expect(rootView.find('.column .pane').length).toBe 2
|
||||
|
||||
@@ -3,13 +3,15 @@ RootView = require 'root-view'
|
||||
Directory = require 'directory'
|
||||
|
||||
describe "TreeView", ->
|
||||
[rootView, project, treeView, rootDirectoryView] = []
|
||||
[rootView, project, treeView, rootDirectoryView, sampleJs, sampleTxt] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(pathToOpen: require.resolve('fixtures/'))
|
||||
project = rootView.project
|
||||
treeView = new TreeView(rootView)
|
||||
rootDirectoryView = treeView.find('> li:first').view()
|
||||
sampleJs = treeView.find('.file:contains(sample.js)')
|
||||
sampleTxt = treeView.find('.file:contains(sample.txt)')
|
||||
|
||||
describe ".initialize(project)", ->
|
||||
it "renders the root of the project and its contents alphabetically with subdirectories first in a collapsed state", ->
|
||||
@@ -71,10 +73,8 @@ describe "TreeView", ->
|
||||
|
||||
describe "when a file is clicked", ->
|
||||
it "opens it in the active editor and selects it", ->
|
||||
sampleJs = treeView.find('.file:contains(sample.js)')
|
||||
sampleTxt = treeView.find('.file:contains(sample.txt)')
|
||||
|
||||
expect(rootView.activeEditor()).toBeUndefined()
|
||||
|
||||
sampleJs.click()
|
||||
expect(sampleJs).toHaveClass 'selected'
|
||||
expect(rootView.activeEditor().buffer.path).toBe require.resolve('fixtures/sample.js')
|
||||
@@ -84,3 +84,21 @@ describe "TreeView", ->
|
||||
expect(treeView.find('.selected').length).toBe 1
|
||||
expect(rootView.activeEditor().buffer.path).toBe require.resolve('fixtures/sample.txt')
|
||||
|
||||
describe "when a new file is opened in the active editor", ->
|
||||
it "is selected in the tree view if visible", ->
|
||||
sampleJs.click()
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
|
||||
expect(sampleTxt).toHaveClass 'selected'
|
||||
expect(treeView.find('.selected').length).toBe 1
|
||||
|
||||
describe "when a different editor becomes active", ->
|
||||
it "selects the file in that is open in that editor", ->
|
||||
sampleJs.click()
|
||||
leftEditor = rootView.activeEditor()
|
||||
rightEditor = leftEditor.splitRight()
|
||||
sampleTxt.click()
|
||||
|
||||
expect(sampleTxt).toHaveClass('selected')
|
||||
leftEditor.focus()
|
||||
expect(sampleJs).toHaveClass('selected')
|
||||
|
||||
@@ -251,8 +251,8 @@ class Editor extends View
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
@buffer = buffer
|
||||
@trigger 'buffer-path-change'
|
||||
@buffer.on "path-change.editor#{@id}", => @trigger 'buffer-path-change'
|
||||
@trigger 'editor-path-change'
|
||||
@buffer.on "path-change.editor#{@id}", => @trigger 'editor-path-change'
|
||||
|
||||
@renderer = new Renderer(@buffer, { maxLineLength: @calcMaxLineLength(), tabText: @tabText })
|
||||
@renderLines()
|
||||
|
||||
@@ -44,6 +44,7 @@ class Pane extends View
|
||||
pane = new Pane(view)
|
||||
this[side](pane)
|
||||
@rootView().adjustPaneDimensions()
|
||||
view.focus?()
|
||||
pane
|
||||
|
||||
remove: (selector, keepData) ->
|
||||
|
||||
@@ -34,6 +34,11 @@ class RootView extends View
|
||||
else
|
||||
@setTitle(@project?.path)
|
||||
|
||||
@on 'active-editor-path-change', (e, path) =>
|
||||
@project.path ?= fs.directory(path) if path
|
||||
@setTitle(path)
|
||||
|
||||
|
||||
@commandPanel = new CommandPanel({rootView: this})
|
||||
|
||||
if pathToOpen?
|
||||
@@ -82,12 +87,10 @@ class RootView extends View
|
||||
|
||||
editor
|
||||
.addClass('active')
|
||||
.on 'buffer-path-change.root-view', =>
|
||||
path = editor.buffer.path
|
||||
@setTitle(path)
|
||||
@project.path ?= fs.directory(path) if path
|
||||
.on 'editor-path-change.root-view', =>
|
||||
@trigger 'active-editor-path-change', editor.buffer.path
|
||||
|
||||
@setTitle(editor.buffer.path)
|
||||
@trigger 'active-editor-path-change', editor.buffer.path
|
||||
|
||||
setTitle: (title='untitled') ->
|
||||
document.title = title
|
||||
|
||||
@@ -35,7 +35,7 @@ class Autocomplete extends View
|
||||
@setCurrentBuffer(@editor.buffer)
|
||||
|
||||
handleEvents: ->
|
||||
@editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)
|
||||
@editor.on 'editor-path-change', => @setCurrentBuffer(@editor.buffer)
|
||||
@editor.on 'before-remove', => @currentBuffer?.off '.autocomplete'
|
||||
|
||||
@editor.on 'autocomplete:attach', => @attach()
|
||||
|
||||
@@ -20,8 +20,10 @@ class TreeView extends View
|
||||
clickedLi.addClass('selected')
|
||||
|
||||
@on 'tree-view:expand-directory', => @selectActiveFile()
|
||||
@rootView.on 'active-editor-path-change', => @selectActiveFile()
|
||||
|
||||
selectActiveFile: ->
|
||||
console.log ""
|
||||
@find('.selected').removeClass('selected')
|
||||
activeFilePath = @rootView.activeEditor()?.buffer.path
|
||||
@find(".file[path='#{activeFilePath}']").addClass('selected')
|
||||
|
||||
Reference in New Issue
Block a user