make the `get` API of editor clearer

pull/3094/head
yann300 7 years ago
parent b4da20e47a
commit d6e91e725c
  1. 4
      src/app.js
  2. 20
      src/app/editor/editor.js
  3. 2
      src/app/files/file-explorer.js
  4. 2
      src/app/files/fileManager.js

@ -896,7 +896,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
return return
} }
var input = editor.get(currentFile) var input = editor.get(currentFile)
if (!input) {
return
}
// if there's no change, don't do anything // if there's no change, don't do anything
if (input === previousInput) { if (input === previousInput) {
return return

@ -169,13 +169,29 @@ function Editor (opts = {}) {
switchSession(path) 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) { this.get = function (path) {
if (currentSession === path) { if (!path || currentSession === path) {
return editor.getValue() 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) { if (editor.getSession() === emptySession) {
return return
} }

@ -28,7 +28,7 @@ function fileExplorer (appAPI, files) {
} }
this.files.event.register('fileExternallyChanged', (path, file) => { 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(), modalDialog(path + ' changed', remixdDialog(),
{ {
label: 'Keep the content displayed in Remix', label: 'Keep the content displayed in Remix',

@ -174,6 +174,7 @@ class FileManager {
var currentFile = this.opt.config.get('currentFile') var currentFile = this.opt.config.get('currentFile')
if (currentFile && this.opt.editor.current()) { if (currentFile && this.opt.editor.current()) {
var input = this.opt.editor.get(currentFile) var input = this.opt.editor.get(currentFile)
if (input) {
var provider = this.fileProviderOf(currentFile) var provider = this.fileProviderOf(currentFile)
if (provider) { if (provider) {
provider.set(currentFile, input) provider.set(currentFile, input)
@ -182,6 +183,7 @@ class FileManager {
} }
} }
} }
}
} }
module.exports = FileManager module.exports = FileManager

Loading…
Cancel
Save