Fixed overwrite bug

pull/5370/head
ioedeveloper 4 years ago
parent faba520e18
commit 934f478074
  1. 15
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx

@ -443,13 +443,14 @@ export const FileExplorer = (props: FileExplorerProps) => {
const fileExternallyChanged = (path: string, file: { content: string }) => { const fileExternallyChanged = (path: string, file: { content: string }) => {
const config = registry.get('config').api const config = registry.get('config').api
const editor = registry.get('editor').api
if (config.get('currentFile') === path && registry.editor.currentContent() && registry.editor.currentContent() !== file.content) { if (config.get('currentFile') === path && editor.currentContent() !== file.content) {
if (filesProvider.isReadOnly(path)) return registry.editor.setText(file.content) if (filesProvider.isReadOnly(path)) return editor.setText(file.content)
modal(path + ' changed', 'This file has been changed outside of Remix IDE.', { modal(path + ' changed', 'This file has been changed outside of Remix IDE.', {
label: 'Replace by the new content', label: 'Replace by the new content',
fn: () => { fn: () => {
registry.editor.setText(file.content) editor.setText(file.content)
} }
}, { }, {
label: 'Keep the content displayed in Remix', label: 'Keep the content displayed in Remix',
@ -505,11 +506,17 @@ export const FileExplorer = (props: FileExplorerProps) => {
const success = await filesProvider.set(name, event.target.result) const success = await filesProvider.set(name, event.target.result)
if (!success) { if (!success) {
modal('File Upload Failed', 'Failed to create file ' + name, { return modal('File Upload Failed', 'Failed to create file ' + name, {
label: 'Close', label: 'Close',
fn: async () => {} fn: async () => {}
}, null) }, null)
} }
const config = registry.get('config').api
const editor = registry.get('editor').api
if ((config.get('currentFile') === name) && (editor.currentContent() !== event.target.result)) {
editor.setText(event.target.result)
}
} }
fileReader.readAsText(file) fileReader.readAsText(file)
} }

Loading…
Cancel
Save