|
150 | 150 | globalThis.qwikOpenInEditor = function (path) {
|
151 | 151 | const isWindows = navigator.platform.includes('Win');
|
152 | 152 | const resolvedURL = new URL(path, isWindows ? origin : srcDir);
|
153 |
| - const prefix = isWindows ? srcDir : srcDir.replace('http://local.local', ''); |
154 |
| - const params = new URLSearchParams(); |
155 |
| - const filePath = |
| 153 | + let filePath = |
156 | 154 | resolvedURL.protocol === 'file:' && resolvedURL.pathname.startsWith('/')
|
157 | 155 | ? resolvedURL.pathname.slice(1)
|
158 |
| - : resolvedURL.pathname; |
159 |
| - let finalPath; |
160 |
| - if (filePath.startsWith(prefix)) { |
161 |
| - finalPath = filePath; |
162 |
| - } else { |
163 |
| - // remove the extra src from filePath as prefix already contains it |
164 |
| - const cleaned = filePath.replace(/^[/\\]?src[/\\]/, ''); |
165 |
| - const sep = isWindows ? '\\' : '/'; |
166 |
| - finalPath = prefix.endsWith(sep) ? prefix + cleaned : prefix + sep + cleaned; |
| 156 | + : resolvedURL.pathname.startsWith('/@fs/') |
| 157 | + ? resolvedURL.pathname.slice(isWindows ? 5 : 4) |
| 158 | + : resolvedURL.pathname; |
| 159 | + if (filePath.startsWith('/src/')) { |
| 160 | + const prefix = isWindows ? srcDir : srcDir.replace('http://local.local', ''); |
| 161 | + filePath = prefix + filePath.slice(4); |
167 | 162 | }
|
168 |
| - params.set('file', finalPath); |
| 163 | + const params = new URLSearchParams(); |
| 164 | + params.set('file', filePath); |
169 | 165 | fetch('/__open-in-editor?' + params.toString());
|
170 | 166 | };
|
171 | 167 | document.addEventListener(
|
|
0 commit comments