Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: inspector bugs #449

Merged
merged 2 commits into from Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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