proposed fix for #59

This commit is contained in:
Vaclav Barta
2022-01-20 10:18:44 +01:00
parent fd479d8671
commit 1f334d6253
2 changed files with 5 additions and 4 deletions

View File

@@ -71,7 +71,7 @@ const HooksEditor = () => {
keepCurrentModel keepCurrentModel
defaultLanguage={snap.files?.[snap.active]?.language} defaultLanguage={snap.files?.[snap.active]?.language}
language={snap.files?.[snap.active]?.language} language={snap.files?.[snap.active]?.language}
path={`file://work/c/${snap.files?.[snap.active]?.name}`} path={`file:///work/c/${snap.files?.[snap.active]?.name}`}
defaultValue={snap.files?.[snap.active]?.content} defaultValue={snap.files?.[snap.active]?.content}
beforeMount={monaco => { beforeMount={monaco => {
if (!snap.editorCtx) { if (!snap.editorCtx) {
@@ -79,7 +79,7 @@ const HooksEditor = () => {
monaco.editor.createModel( monaco.editor.createModel(
file.content, file.content,
file.language, file.language,
monaco.Uri.parse(`file://work/c/${file.name}`) monaco.Uri.parse(`file:///work/c/${file.name}`)
) )
); );
} }

View File

@@ -4,8 +4,9 @@ import state from '../index';
// Saves the current editor content to global state // Saves the current editor content to global state
export const saveFile = (showToast: boolean = true) => { export const saveFile = (showToast: boolean = true) => {
const editorModels = state.editorCtx?.getModels(); const editorModels = state.editorCtx?.getModels();
const sought = state.files[state.active].name;
const currentModel = editorModels?.find((editorModel) => { const currentModel = editorModels?.find((editorModel) => {
return editorModel.uri.path === `/c/${state.files[state.active].name}`; return editorModel.uri.path.endsWith(sought);
}); });
if (state.files.length > 0) { if (state.files.length > 0) {
state.files[state.active].content = currentModel?.getValue() || ""; state.files[state.active].content = currentModel?.getValue() || "";
@@ -13,4 +14,4 @@ export const saveFile = (showToast: boolean = true) => {
if (showToast) { if (showToast) {
toast.success("Saved successfully", { position: "bottom-center" }); toast.success("Saved successfully", { position: "bottom-center" });
} }
}; };