Skip to content

Commit 33f508c

Browse files
committed
feat: use relative path instead of the image file name directly
1 parent 84dc658 commit 33f508c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define(function (require, exports, module) {
3030
const CodeMirror = require("thirdparty/CodeMirror/lib/codemirror");
3131
const ProjectManager = require("project/ProjectManager");
3232
const FileSystem = require("filesystem/FileSystem");
33+
const PathUtils = require("thirdparty/path-utils/path-utils");
3334

3435
/**
3536
* This function syncs text content changes between the original source code
@@ -693,7 +694,18 @@ define(function (require, exports, module) {
693694
if (err) {
694695
console.error('Failed to save image:', err);
695696
} else {
696-
_updateImageSrcAttribute(tagId, uniqueFilename);
697+
// once the image is saved, we need to update the source code
698+
// so we get the relative path between the current file and the image file
699+
// and that relative path is written as the src value
700+
const editor = _getEditorAndValidate(tagId);
701+
if (editor) {
702+
const htmlFilePath = editor.document.file.fullPath;
703+
const relativePath = PathUtils.makePathRelative(targetPath, htmlFilePath);
704+
_updateImageSrcAttribute(tagId, relativePath);
705+
} else {
706+
// if editor is not available we directly write the image file name as the src value
707+
_updateImageSrcAttribute(tagId, uniqueFilename);
708+
}
697709
}
698710
});
699711
})

0 commit comments

Comments
 (0)