Skip to content

Commit 2a38b99

Browse files
authored
Fix: inspector bugs (#449)
* fix: svelte-inspector ignore navigation keys while not enabled * fix: svelte-inspector mousemove handler should activate event.target if it is selectable
1 parent 396f04f commit 2a38b99

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

.changeset/eighty-dingos-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
svelte-inspector: select hovered element instead of parent on mousemouse

.changeset/mighty-tigers-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
svelte-inspector: ignore navigation keys while not enabled

packages/vite-plugin-svelte/src/ui/inspector/Inspector.svelte

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@
3636
y = event.y;
3737
}
3838
39-
function find_selectable_parent(el) {
40-
do {
39+
function find_selectable_parent(el, include_self = false) {
40+
if (!include_self) {
4141
el = el.parentNode;
42+
}
43+
while (el) {
4244
if (is_selectable(el)) {
4345
return el;
4446
}
45-
} while (el);
47+
el = el.parentNode;
48+
}
4649
}
4750
4851
function find_selectable_child(el) {
@@ -89,8 +92,8 @@
8992
return true;
9093
}
9194
92-
function mouseover(event) {
93-
const el = find_selectable_parent(event.target);
95+
function mouseover({ target }) {
96+
const el = find_selectable_parent(target, true);
9497
activate(el, false);
9598
}
9699
@@ -171,14 +174,16 @@
171174
if (options.holdMode && enabled) {
172175
enabled_ts = Date.now();
173176
}
174-
} else if (is_nav(event)) {
175-
const el = find_selectable_for_nav(event.key);
176-
if (el) {
177-
activate(el);
178-
stop(event);
177+
} else if (enabled) {
178+
if (is_nav(event)) {
179+
const el = find_selectable_for_nav(event.key);
180+
if (el) {
181+
activate(el);
182+
stop(event);
183+
}
184+
} else if (is_open(event)) {
185+
open_editor(event);
179186
}
180-
} else if (is_open(event)) {
181-
open_editor(event);
182187
}
183188
}
184189
@@ -217,10 +222,10 @@
217222
218223
function activate_initial_el() {
219224
const hov = innermost_hover_el();
220-
let el = is_selectable(hov) ? hov : find_selectable_parent(hov);
225+
let el = find_selectable_parent(hov, true);
221226
if (!el) {
222227
const act = document.activeElement;
223-
el = is_selectable(act) ? act : find_selectable_parent(act);
228+
el = find_selectable_parent(act, true);
224229
}
225230
if (!el) {
226231
el = find_selectable_child(document.body);

0 commit comments

Comments
 (0)