fix element

pull/3094/head
yann300 7 years ago
parent 52914fffa3
commit 26c3825311
  1. 45
      src/app/files/file-explorer.js

@ -53,14 +53,12 @@ var css = csjs`
` `
module.exports = fileExplorer module.exports = fileExplorer
var focusElement = null
var focusPath = null
function fileExplorer (appAPI, files) { function fileExplorer (appAPI, files) {
var self = this var self = this
this.events = new EventManager() this.events = new EventManager()
this.files = files this.files = files
this.focusElement = null
this.focusPath = null
function remixdDialog () { function remixdDialog () {
return yo`<div>This file has been changed outside of Remix IDE.</div>` return yo`<div>This file has been changed outside of Remix IDE.</div>`
} }
@ -117,7 +115,18 @@ function fileExplorer (appAPI, files) {
}) })
self.treeView.event.register('leafClick', function (key, data, label) { self.treeView.event.register('leafClick', function (key, data, label) {
self.events.trigger('focus', [key]) if (self.focusElement) {
self.focusElement.classList.remove(css.hasFocus)
self.focusElement = null
self.focusPath = null
}
self.focusElement = self.treeView.labelAt(key)
if (self.focusElement) {
self.focusElement.classList.add(css.hasFocus)
self.focusPath = key
self.events.trigger('focus', [key])
appAPI.config.set('currentFile', key)
}
}) })
self.treeView.event.register('nodeClick', function (path, childrenContainer) { self.treeView.event.register('nodeClick', function (path, childrenContainer) {
@ -130,8 +139,7 @@ function fileExplorer (appAPI, files) {
if (error) console.error(error) if (error) console.error(error)
if (!fileTree) return if (!fileTree) return
var newTree = normalize(path, fileTree) var newTree = normalize(path, fileTree)
newTree = self.treeView.renderProperties(newTree, false) self.treeView.updateNodeFromJSON(path, newTree, false)
self.treeView.updateNode(path, newTree)
}) })
}) })
@ -145,16 +153,10 @@ function fileExplorer (appAPI, files) {
} }
appAPI.event.register('currentFileChanged', (newFile, explorer) => { appAPI.event.register('currentFileChanged', (newFile, explorer) => {
if (focusElement && newFile !== focusPath) { if (self.focusElement && explorer.type !== files.type && self.focusPath !== newFile) {
focusElement.classList.remove(css.hasFocus) self.focusElement.classList.remove(css.hasFocus)
} self.focusElement = null
if (explorer === files) { self.focusPath = null
focusElement = self.treeView.labelAt(newFile)
if (focusElement) {
focusPath = newFile
focusElement.classList.add(css.hasFocus)
appAPI.config.set('currentFile', newFile)
}
} }
}) })
fileEvents.register('fileRemoved', fileRemoved) fileEvents.register('fileRemoved', fileRemoved)
@ -273,8 +275,13 @@ function fileExplorer (appAPI, files) {
if (error) console.error(error) if (error) console.error(error)
if (!fileTree) return if (!fileTree) return
fileTree = normalize(folderpath, fileTree) fileTree = normalize(folderpath, fileTree)
var newTree = self.treeView.renderProperties(fileTree, false) self.treeView.updateNodeFromJSON(folderpath, fileTree, false)
self.treeView.updateNode(folderpath, newTree) self.focusElement = self.treeView.labelAt(self.focusPath)
// TODO: here we update the selected file (it applicable)
// cause we are refreshing the interface of the whole directory when there's a new file.
if (self.focusElement && !self.focusElement.classList.contains(css.hasFocus)) {
self.focusElement.classList.add(css.hasFocus)
}
}) })
} }
}) })

Loading…
Cancel
Save