Skip to content

Commit

Permalink
Fix Monaco URI handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thorpelawrence committed Jul 23, 2017
1 parent ddfdbdc commit 52b0796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spectrum-editor",
"version": "1.1.0",
"version": "1.1.1",
"main": "main.js",
"scripts": {
"start": "electron .",
Expand Down
14 changes: 8 additions & 6 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,25 @@ loader().then((monaco) => {

ipcRenderer.on('open-file', (e, path) => {
if (path) {
if (monaco.editor.getModel(path)) {
editor.setModel(monaco.editor.getModel(path))
let uri = monaco.Uri.file(path)
if (monaco.editor.getModel(uri)) {
editor.setModel(monaco.editor.getModel(uri))
}
else {
fs.readFile(path, 'utf8', (err, data) => {
if (err) console.error(err)
editor.setModel(monaco.editor.createModel(data, null, path))
editor.setModel(monaco.editor.createModel(data, null, uri))
})
}
}
})

ipcRenderer.on('save-file', (e, saveAs) => {
let path = editor.getModel().uri
if (saveAs || typeof path !== "string") {
let uri = editor.getModel().uri
let path = uri.scheme !== "inmemory" ? uri.fsPath : null
if (saveAs || !path) {
path = dialog.showSaveDialog(win, {
defaultPath: typeof path === "string" ? path : null
defaultPath: path
})
}
if (path) {
Expand Down

0 comments on commit 52b0796

Please sign in to comment.