From f5e87ea4921a6c06f5c5775ffc382df710af1190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rokas=20Ge=C4=8Das?= Date: Sun, 4 Feb 2018 17:20:51 +0200 Subject: [PATCH 1/2] config prop prefixPathWithCurrentDirectory implemented, _workspacePath fixed --- package.json | 5 +++++ src/extension.ts | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b583660..a5f5b85 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,11 @@ ".js" ], "description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)" + }, + "relativePath.prefixPathWithCurrentDirectory": { + "type": "boolean", + "default": false, + "description": "Returned relative path is always prefixed with ./" } } } diff --git a/src/extension.ts b/src/extension.ts index affbd85..212ed20 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -85,8 +85,8 @@ class RelativePath { const editor = window.activeTextEditor; if (editor) { const res = editor.document.uri; - const folder = workspace.getWorkspaceFolder(res) - return folder.uri.fsPath; + const folder = workspace.getWorkspaceFolder(res); + return folder.uri.fsPath.replace(/\\/g, "/"); } } // Purely updates the files @@ -203,13 +203,11 @@ class RelativePath { const currentItemPath = editor.document.fileName.replace(/\\/g, "/").replace(this._workspacePath, ""); let relativeUrl: string = path.relative(currentItemPath, targetPath).replace(".", "").replace(/\\/g, "/"); - if (this._configuration.removeExtension) { - relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf(".")); - } else if (this.excludeExtensionsFor(relativeUrl)) { + if (this._configuration.removeExtension || this.excludeExtensionsFor(relativeUrl)) { relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf(".")); } - if (relativeUrl.startsWith("./../")) { + if (!this._configuration.prefixPathWithCurrentDirectory && relativeUrl.startsWith("./../")) { relativeUrl = relativeUrl.substring(2, relativeUrl.length); } From 69ae5bb87d407164e15f6a0a54bc05fa75663f9b Mon Sep 17 00:00:00 2001 From: rokas Date: Sun, 4 Feb 2018 21:19:00 +0200 Subject: [PATCH 2/2] prefixPathWithCurrentDirectory reanemed to removeLeadingDot as it as previosly called --- package.json | 6 +++--- src/extension.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a5f5b85..98002b4 100644 --- a/package.json +++ b/package.json @@ -67,10 +67,10 @@ ], "description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)" }, - "relativePath.prefixPathWithCurrentDirectory": { + "relativePath.removeLeadingDot": { "type": "boolean", - "default": false, - "description": "Returned relative path is always prefixed with ./" + "default": true, + "description": "Removes the leading ./ character when the path is pointing to a parent folder." } } } diff --git a/src/extension.ts b/src/extension.ts index 212ed20..df0bcc4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -207,7 +207,7 @@ class RelativePath { relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf(".")); } - if (!this._configuration.prefixPathWithCurrentDirectory && relativeUrl.startsWith("./../")) { + if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) { relativeUrl = relativeUrl.substring(2, relativeUrl.length); }