Skip to content

Commit a480c2a

Browse files
simplified logic
1 parent 74bb5a8 commit a480c2a

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

src/lib/run.js

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -498,67 +498,25 @@ async function run(
498498
function removePrefix(str, prefix) {
499499
console.log("-----------------")
500500
console.log("removing " + prefix + " from " + str)
501+
const result = str.startsWith(prefix) ? str.slice(prefix.length) : str;
502+
console.log("result : "+result)
501503
console.log("-----------------")
502-
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
504+
return result
503505
}
504506

505507
/**
506508
* Opens the preview in browser
507509
*/
508510
function openBrowser() {
509-
console.log("Path name", pathName);
510-
console.log("File parent",pathName)
511-
512511
//get the project url
513512
let rootFolder = addedFolder[0].url
514513

515-
if (rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) {
516-
if (rootFolder.includes("?")) {
517-
rootFolder = rootFolder.split("?")[0];
518-
}
519-
}
520-
521-
if (pathName.startsWith("ftp:") || pathName.startsWith("sftp:")) {
522-
if (pathName.includes("?")) {
523-
pathName = pathName.split("?")[0];
524-
}
525-
}
526-
527514
//append path data
528515
if (rootFolder === "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome") {
529516
rootFolder = "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome::/data/data/com.termux/files/home/"
530517
}
531518

532-
console.log("Root", rootFolder)
533-
534-
//remove the project prefix from the file parent path name
535-
//this will give us the path relative to the project folder
536-
/** @type {string} */
537-
let filePath = removePrefix(pathName, rootFolder)
538-
539-
let oldFilePath = filePath
540-
filePath = pathName.split("::")[1];
541-
if (!filePath) {
542-
filePath = oldFilePath
543-
}
544-
545-
console.log("File path", filePath);
546-
547-
548-
549-
//add the filename to the path
550-
//this will give us the full path to the file relative to the project folder
551-
if (filePath.endsWith("/")) {
552-
filePath += filename;
553-
} else {
554-
filePath = filePath + "/" + filename;
555-
}
556-
557-
558-
let path = removePrefix(removePrefix(removePrefix(filePath, rootFolder),"primary:"+addedFolder[0].title),"/")
559-
560-
console.log("Path", path);
561-
519+
const path = removePrefix(Url.join(editorManager.activeFile.location,filename),rootFolder)
562520

563521
const src = `http://localhost:${port}/${path}`;
564522

0 commit comments

Comments
 (0)