Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const state = {
settings: {
testIdAttribute: 'data-testid',
},
pointerInside: false,
};

function postMessage(action) {
Expand Down Expand Up @@ -106,12 +107,16 @@ function Sandbox() {
<div
className="pr-1 relative w-screen h-screen overflow-hidden"
onMouseEnter={() => {
state.pointerInside = true;
state.highlighter?.clear();
state.highlighter?.start({ stopOnClick: false, blockEvents: false });
}}
onMouseLeave={() => {
state.highlighter?.stop();
state.highlighter.highlight({ nodes: state.queriedNodes });
state.pointerInside = false;

postMessage({ type: 'HOVER_NODE', payload: null });
}}
>
<Scrollable forwardedRef={setRootNode} id="sandbox" />
Expand All @@ -120,7 +125,11 @@ function Sandbox() {
}

function onSelectNode(node, { origin }) {
if (!origin || origin === 'script') {
// onSelectNode can be triggered after onMouseLeave has already been called.
// This makes it impossible to clear hover state. That's why we maintain and
// check a boolean to see if the pointer is inside the sandbox, before
// dispatching events.
if (!origin || origin === 'script' || !state.pointerInside) {
return;
}

Expand Down