Merge pull request #15692 from UziTech/pane-onDidChangePath

Pane on did change path
This commit is contained in:
Max Brunsfeld
2017-09-28 11:51:12 -07:00
committed by GitHub
2 changed files with 55 additions and 0 deletions

View File

@@ -113,6 +113,53 @@ describe "PaneElement", ->
expect(paneElement.dataset.activeItemPath).toBeUndefined()
expect(paneElement.dataset.activeItemName).toBeUndefined()
describe "when the path of the item changes", ->
[item1, item2] = []
beforeEach ->
item1 = document.createElement('div')
item1.path = '/foo/bar.txt'
item1.changePathCallbacks = []
item1.setPath = (path) ->
@path = path
callback() for callback in @changePathCallbacks
return
item1.getPath = -> @path
item1.onDidChangePath = (callback) ->
@changePathCallbacks.push callback
return dispose: =>
@changePathCallbacks = @changePathCallbacks.filter (f) -> f isnt callback
item2 = document.createElement('div')
pane.addItem(item1)
pane.addItem(item2)
it "changes the file path and file name data attributes on the pane if the active item path is changed", ->
expect(paneElement.dataset.activeItemPath).toBe '/foo/bar.txt'
expect(paneElement.dataset.activeItemName).toBe 'bar.txt'
item1.setPath "/foo/bar1.txt"
expect(paneElement.dataset.activeItemPath).toBe '/foo/bar1.txt'
expect(paneElement.dataset.activeItemName).toBe 'bar1.txt'
pane.activateItem(item2)
expect(paneElement.dataset.activeItemPath).toBeUndefined()
expect(paneElement.dataset.activeItemName).toBeUndefined()
item1.setPath "/foo/bar2.txt"
expect(paneElement.dataset.activeItemPath).toBeUndefined()
expect(paneElement.dataset.activeItemName).toBeUndefined()
pane.activateItem(item1)
expect(paneElement.dataset.activeItemPath).toBe '/foo/bar2.txt'
expect(paneElement.dataset.activeItemName).toBe 'bar2.txt'
describe "when an item is removed from the pane", ->
describe "when the destroyed item is an element", ->
it "removes the item from the itemViews div", ->

View File

@@ -79,6 +79,7 @@ class PaneElement extends HTMLElement
activeItemChanged: (item) ->
delete @dataset.activeItemName
delete @dataset.activeItemPath
@changePathDisposable?.dispose()
return unless item?
@@ -89,6 +90,12 @@ class PaneElement extends HTMLElement
@dataset.activeItemName = path.basename(itemPath)
@dataset.activeItemPath = itemPath
if item.onDidChangePath?
@changePathDisposable = item.onDidChangePath =>
itemPath = item.getPath()
@dataset.activeItemName = path.basename(itemPath)
@dataset.activeItemPath = itemPath
unless @itemViews.contains(itemView)
@itemViews.appendChild(itemView)
@@ -119,6 +126,7 @@ class PaneElement extends HTMLElement
paneDestroyed: ->
@subscriptions.dispose()
@changePathDisposable?.dispose()
flexScaleChanged: (flexScale) ->
@style.flexGrow = flexScale