only mouse1 clicks should cause posts to open

This commit is contained in:
ari melody 2024-07-01 07:58:48 +01:00
parent fe540d791b
commit 4e9acb6502
Signed by: ari
GPG key ID: CF99829C92678188
2 changed files with 19 additions and 6 deletions

View file

@ -32,9 +32,15 @@
let mouse_pos = { top: 0, left: 0 }; let mouse_pos = { top: 0, left: 0 };
function gotoPost() { function gotoPost(event) {
if (focused) return; if (focused) return;
if (event && event.key && event.key !== "Enter") return; if (event) {
if (event.type == "mouseup" && (
event.button !== 0 ||
event.shiftKey ||
event.ctrlKey)) return;
if (event.key && event.key !== "Enter") return;
}
goto(`/post/${post.id}`); goto(`/post/${post.id}`);
} }
@ -62,7 +68,7 @@
aria-label={aria_label} aria-label={aria_label}
bind:this={el} bind:this={el}
on:mousedown={e => {mouse_pos.left = e.pageX; mouse_pos.top = e.pageY}} on:mousedown={e => {mouse_pos.left = e.pageX; mouse_pos.top = e.pageY}}
on:mouseup={e => {if (e.pageX == mouse_pos.left && e.pageY == mouse_pos.top) gotoPost()}} on:mouseup={e => {if (e.pageX == mouse_pos.left && e.pageY == mouse_pos.top) gotoPost(e)}}
on:keydown={gotoPost}> on:keydown={gotoPost}>
<PostHeader post={post} /> <PostHeader post={post} />
<Body post={post} /> <Body post={post} />

View file

@ -16,8 +16,15 @@
let mouse_pos = { top: 0, left: 0 }; let mouse_pos = { top: 0, left: 0 };
function gotoPost() { function gotoPost(event) {
if (event && event.key && event.key !== "Enter") return; if (event) {
if (event.type == "mouseup" && (
event.button !== 0 ||
event.shiftKey ||
event.ctrlKey)) return;
if (event.key && event.key !== "Enter") return;
}
goto(`/post/${post.id}`); goto(`/post/${post.id}`);
} }
</script> </script>
@ -32,7 +39,7 @@
class="post-reply" class="post-reply"
aria-label={aria_label} aria-label={aria_label}
on:mousedown={e => {mouse_pos.left = e.pageX; mouse_pos.top = e.pageY}} on:mousedown={e => {mouse_pos.left = e.pageX; mouse_pos.top = e.pageY}}
on:mouseup={e => {if (e.pageX == mouse_pos.left && e.pageY == mouse_pos.top) gotoPost()}} on:mouseup={e => {if (e.pageX == mouse_pos.left && e.pageY == mouse_pos.top) gotoPost(e)}}
on:keydown={gotoPost}> on:keydown={gotoPost}>
<div class="line"></div> <div class="line"></div>