Skip to content

Commit aec622b

Browse files
authored
fix: fix up open editor edge cases 🍊 (#7791)
* fix: fix up open editor edge cases * chore: change split logic * chore: change logic 🍟 * chore: change logic 🍿 * chore: change logic πŸ“Œ * chore: change logic πŸ• * chore: add final polish πŸ₯‘
1 parent f704aed commit aec622b

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

β€Žpackages/qwik/src/optimizer/src/plugins/click-to-component.html

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,18 @@
150150
globalThis.qwikOpenInEditor = function (path) {
151151
const isWindows = navigator.platform.includes('Win');
152152
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 =
156154
resolvedURL.protocol === 'file:' && resolvedURL.pathname.startsWith('/')
157155
? 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);
167162
}
168-
params.set('file', finalPath);
163+
const params = new URLSearchParams();
164+
params.set('file', filePath);
169165
fetch('/__open-in-editor?' + params.toString());
170166
};
171167
document.addEventListener(

0 commit comments

Comments
Β (0)