mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 12:36:35 +00:00
Always fire mouseup on element that had mousedown (#850)
This commit is contained in:
parent
f7992718f6
commit
8b91e6db79
1 changed files with 24 additions and 8 deletions
|
|
@ -27,6 +27,30 @@ function handleMouseEventDispatch(node, event, eventName) {
|
|||
const x = event.clientX - rect.left;
|
||||
const y = event.clientY - rect.top;
|
||||
node.js_trigger(eventName, x, y);
|
||||
|
||||
if (event.nativeEvent.type === "mousedown") {
|
||||
// We need to persist the react event so we can access the target
|
||||
event.persist();
|
||||
document.addEventListener("mouseup", function globalMouseUp(ev) {
|
||||
document.removeEventListener("mouseup", globalMouseUp);
|
||||
// Create an object that looks and acts like an event, but has mixed
|
||||
// properties from original mousedown event and new mouseup event
|
||||
const fakeEvent = {
|
||||
target: event.target,
|
||||
clientX: ev.clientX,
|
||||
clientY: ev.clientY,
|
||||
nativeEvent: {
|
||||
type: "mouseup",
|
||||
},
|
||||
stopPropagation: ev.stopPropagation.bind(ev),
|
||||
};
|
||||
handleMouseEventDispatch(
|
||||
node,
|
||||
fakeEvent,
|
||||
eventName === "onLeftButtonDown" ? "onLeftButtonUp" : "onRightButtonUp"
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseButtonEventDispatch(
|
||||
|
|
@ -53,14 +77,6 @@ function GuiObjectEvents({ node, children }) {
|
|||
"onRightButtonDown"
|
||||
)
|
||||
}
|
||||
onMouseUp={e =>
|
||||
handleMouseButtonEventDispatch(
|
||||
node,
|
||||
e,
|
||||
"onLeftButtonUp",
|
||||
"onRightButtonUp"
|
||||
)
|
||||
}
|
||||
onDoubleClick={e =>
|
||||
handleMouseButtonEventDispatch(
|
||||
node,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue