Skip to content

Commit

Permalink
fix: correctly highlight hovered node (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb authored Oct 16, 2023
1 parent 5d19e5e commit f716b50
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/lib/nodes/Anchor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<style>
div {
width: 100%;
color: rgb(151, 164, 179);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/nodes/Block.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<style>
div {
width: 100%;
display: flex;
color: rgb(151, 164, 179);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/nodes/Element.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

<style>
div {
width: 100%;
display: flex;
flex-wrap: wrap;
}
Expand Down
16 changes: 2 additions & 14 deletions src/lib/nodes/Node.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
{@const left = depth * 12 + 4}

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<li
class:flash
bind:this={node.dom}
on:animationend={() => (flash = false)}
on:click|stopPropagation={() => selected.set(node)}
on:mouseenter|stopPropagation={() => {
on:mousemove|stopPropagation={() => {
if ($hovered?.id === node.id) return;
background.send('ext/highlight', node.id);
hovered.set(node);
}}
Expand Down Expand Up @@ -144,15 +144,6 @@
background: #e0e0e2;
}
/* li:hover,
li.hovered {
background: #f0f9fe;
}
li.selected {
background: rgb(0, 116, 232);
color: #ffffff;
} */
li.flash :global(> :first-child),
li.flash :global(> :first-child *),
li :global(.flash),
Expand All @@ -175,13 +166,10 @@
background: #f0f9fe;
}
:global(.dark) li:hover,
/* :global(.dark) li.hovered, */
:global(.dark) li :global(.hover) {
background: rgb(53, 59, 72);
}
/* :global(.dark) li.selected, */
:global(.dark) li :global(.selected),
:global(.dark) li :global(.selected *),
:global(.dark) li :global(.hover.selected) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/nodes/Slot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<style>
div {
width: 100%;
display: flex;
}
</style>
13 changes: 6 additions & 7 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
function interactive({ type }: (typeof $root)[number]) {
return $visibility[type] && type !== 'text' && type !== 'anchor';
}
function reset() {
background.send('ext/highlight', null);
hovered.set(undefined);
}
</script>

<svelte:window
Expand Down Expand Up @@ -112,12 +117,7 @@
</Button>
</Toolbar>

<ul
on:mouseleave={() => {
background.send('ext/highlight', null);
hovered.set(undefined);
}}
>
<ul on:mousemove|self={reset} on:mouseleave={reset}>
{#each $root as node (node.id)}
<Node {node} />
{/each}
Expand Down Expand Up @@ -161,7 +161,6 @@
ul {
overflow: auto;
padding-left: 0.5rem;
}
h2 {
Expand Down

0 comments on commit f716b50

Please sign in to comment.