From d6e91e725cd271c8157102a05330ae85ddd17810 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 23 Apr 2018 09:04:02 +0200 Subject: [PATCH] make the `get` API of editor clearer --- src/app.js | 4 +++- src/app/editor/editor.js | 20 ++++++++++++++++++-- src/app/files/file-explorer.js | 2 +- src/app/files/fileManager.js | 12 +++++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/app.js b/src/app.js index c70d41007e..1d948b6c35 100644 --- a/src/app.js +++ b/src/app.js @@ -896,7 +896,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org return } var input = editor.get(currentFile) - + if (!input) { + return + } // if there's no change, don't do anything if (input === previousInput) { return diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index 6b4a6750b5..fd96b107a5 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -169,13 +169,29 @@ function Editor (opts = {}) { switchSession(path) } + /** + * returns the content of the specified session @arg path + * if @arg path is not provided, the content of the current editing session is returned + * + * @param {String} path - path of th file in edition + * @return {String} content of the file referenced by @arg path + */ this.get = function (path) { - if (currentSession === path) { + if (!path || currentSession === path) { return editor.getValue() + } else if (sessions[path]) { + sessions[path].getValue() } } - this.current = function (path) { + /** + * returns the path of the currently editing file + * returns `undefined` if no session is being editer + * + * @param {String} path - path of th file in edition + * @return {String} content of the file referenced by @arg path + */ + this.current = function () { if (editor.getSession() === emptySession) { return } diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index dc862123fd..9a40e65144 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -28,7 +28,7 @@ function fileExplorer (appAPI, files) { } this.files.event.register('fileExternallyChanged', (path, file) => { - if (appAPI.config.get('currentFile') === path && appAPI.currentContent() !== file.content) { + if (appAPI.config.get('currentFile') === path && appAPI.currentContent() && appAPI.currentContent() !== file.content) { modalDialog(path + ' changed', remixdDialog(), { label: 'Keep the content displayed in Remix', diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 5097ee901b..631c7bbdde 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -174,11 +174,13 @@ class FileManager { var currentFile = this.opt.config.get('currentFile') if (currentFile && this.opt.editor.current()) { var input = this.opt.editor.get(currentFile) - var provider = this.fileProviderOf(currentFile) - if (provider) { - provider.set(currentFile, input) - } else { - console.log('cannot save ' + currentFile + '. Does not belong to any explorer') + if (input) { + var provider = this.fileProviderOf(currentFile) + if (provider) { + provider.set(currentFile, input) + } else { + console.log('cannot save ' + currentFile + '. Does not belong to any explorer') + } } } }