Skip to content

Commit

Permalink
Fix: inspector bugs (#449)
Browse files Browse the repository at this point in the history
* fix: svelte-inspector ignore navigation keys while not enabled

* fix: svelte-inspector mousemove handler should activate event.target if it is selectable
  • Loading branch information
dominikg committed Sep 22, 2022
1 parent 396f04f commit 2a38b99
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-dingos-dance.md
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

svelte-inspector: select hovered element instead of parent on mousemouse
5 changes: 5 additions & 0 deletions .changeset/mighty-tigers-sell.md
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

svelte-inspector: ignore navigation keys while not enabled
33 changes: 19 additions & 14 deletions packages/vite-plugin-svelte/src/ui/inspector/Inspector.svelte
Expand Up @@ -36,13 +36,16 @@
y = event.y;
}
function find_selectable_parent(el) {
do {
function find_selectable_parent(el, include_self = false) {
if (!include_self) {
el = el.parentNode;
}
while (el) {
if (is_selectable(el)) {
return el;
}
} while (el);
el = el.parentNode;
}
}
function find_selectable_child(el) {
Expand Down Expand Up @@ -89,8 +92,8 @@
return true;
}
function mouseover(event) {
const el = find_selectable_parent(event.target);
function mouseover({ target }) {
const el = find_selectable_parent(target, true);
activate(el, false);
}
Expand Down Expand Up @@ -171,14 +174,16 @@
if (options.holdMode && enabled) {
enabled_ts = Date.now();
}
} else if (is_nav(event)) {
const el = find_selectable_for_nav(event.key);
if (el) {
activate(el);
stop(event);
} else if (enabled) {
if (is_nav(event)) {
const el = find_selectable_for_nav(event.key);
if (el) {
activate(el);
stop(event);
}
} else if (is_open(event)) {
open_editor(event);
}
} else if (is_open(event)) {
open_editor(event);
}
}
Expand Down Expand Up @@ -217,10 +222,10 @@
function activate_initial_el() {
const hov = innermost_hover_el();
let el = is_selectable(hov) ? hov : find_selectable_parent(hov);
let el = find_selectable_parent(hov, true);
if (!el) {
const act = document.activeElement;
el = is_selectable(act) ? act : find_selectable_parent(act);
el = find_selectable_parent(act, true);
}
if (!el) {
el = find_selectable_child(document.body);
Expand Down

0 comments on commit 2a38b99

Please sign in to comment.