diff --git a/src/app.js b/src/app.js index 5a15ec9817..308ebe6482 100644 --- a/src/app.js +++ b/src/app.js @@ -498,9 +498,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org fileManager.switchFile(path) }, event: fileManager.event, - currentFile: function () { - return config.get('currentFile') - }, + config: config, currentContent: function () { return editor.get(config.get('currentFile')) }, @@ -516,18 +514,14 @@ Please make a backup of your contracts and start using http://remix.ethereum.org filePanel.event.register('resize', delta => self._adjustLayout('left', delta)) - var previouslyOpenedFile = config.get('currentFile') - if (previouslyOpenedFile) { + setTimeout(function initOpenFile () { + var previouslyOpenedFile = config.get('currentFile') || 'browser/ballot.sol' + config.set('currentFile', null) filesProviders['browser'].get(previouslyOpenedFile, (error, content) => { - if (!error && content) { - fileManager.switchFile(previouslyOpenedFile) - } else { - fileManager.switchFile() - } + if (!error && content) fileManager.switchFile(previouslyOpenedFile) + else fileManager.switchFile('browser/ballot.sol') }) - } else { - fileManager.switchFile() - } + }, 0) // ----------------- Renderer ----------------- var rendererAPI = { diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 29377b092c..9cd8b1ae94 100755 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -149,6 +149,8 @@ function fileExplorer (appAPI, files) { if (explorer === files) { fileFocus(newFile) } else { + var currentFile = appAPI.config.get('currentFile') + if (currentFile === newFile) return unfocus(focusElement) } }) @@ -157,7 +159,6 @@ function fileExplorer (appAPI, files) { fileEvents.register('fileRenamedError', fileRenamedError) fileEvents.register('fileAdded', fileAdded) - var filepath = null var textUnderEdit = null var textInRename = false @@ -332,15 +333,41 @@ function fileExplorer (appAPI, files) { }) } + function expandPathTo (filePath, cb) { + var label = self.element.querySelector(`label[data-path="${filePath}"]`) + if (label) cb() + var arr = filePath.split('/') + var filename = arr.pop() + var path = arr.shift() + var fullpath = path + expand(fullpath, path, function next () { + path = arr.shift() + if (path) { + fullpath += '/' + path + expand(fullpath, path, next) + } else { + var label = self.element.querySelector(`label[data-path$="${filename}"]`) + focus.call(getLiFrom(label), {}) + cb() + } + }) + function expand (path, step, next) { + label = self.element.querySelector(`label[data-path="${step}"]`) || + self.element.querySelector(`label[data-path="${path}"]`) + if (label) var li = label.parentElement.parentElement.parentElement + if (!label || path === step && !li.children[1].children.length) { + var currentTree = self.treeView.nodeAt(path) + var caret = currentTree.parentElement.firstElementChild.firstElementChild + caret.click() + next() + } else next() + } + } + function fileFocus (path) { + var filepath = appAPI.config.get('currentFile') if (filepath === path) return - filepath = path - setTimeout(function focusNode () { - // @TODO: fix file tree expand logic to account for async remixd loading logic - var el = getElement(filepath) - expandPathTo(el) - setTimeout(function focusNode () { el.click() }, 0) - }, 0) + expandPathTo(path, function () { appAPI.config.set('currentFile', path) }) } function fileRemoved (filepath) { @@ -435,13 +462,6 @@ function removeSubtree (files, path, isFolder) { if (isFolder) files.remove(path) } -function expandPathTo (li) { - while ((li = li.parentElement.parentElement) && li.tagName === 'LI') { - var caret = li.firstChild.firstChild - if (caret.classList.contains('fa-caret-right')) caret.click() // expand - } -} - fileExplorer.prototype.init = function () { var self = this self.files.resolveDirectory('/', (error, files) => { diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 9a5875b650..8acaaa2a01 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -47,6 +47,7 @@ class FileManager { self.switchFile(Object.keys(self.tabbedFiles)[0]) } else { opt.editor.displayEmptyReadOnlySession() + self.opt.config.set('currentFile', '') } return false }) @@ -98,7 +99,6 @@ class FileManager { // Display files that have already been selected refreshTabs (newfile) { - var self = this if (newfile) { this.tabbedFiles[newfile] = newfile } @@ -109,14 +109,14 @@ class FileManager { for (var file in this.tabbedFiles) { $filesEl.append(yo`