From 683db3ab253e60d2a5ba14d0f348e5285704fea8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 20 Nov 2024 16:56:35 +0100 Subject: [PATCH] Add ability to middle-mouse click posts in web UI (#32988) --- app/javascript/mastodon/components/status.jsx | 57 ++++++++----------- .../mastodon/components/status_content.jsx | 4 +- .../components/embedded_status.tsx | 12 +++- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/app/javascript/mastodon/components/status.jsx b/app/javascript/mastodon/components/status.jsx index 95ea53521f..669eb22cb6 100644 --- a/app/javascript/mastodon/components/status.jsx +++ b/app/javascript/mastodon/components/status.jsx @@ -3,6 +3,8 @@ import PropTypes from 'prop-types'; import { injectIntl, defineMessages, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; +import { Link } from 'react-router-dom'; + import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; @@ -164,32 +166,18 @@ class Status extends ImmutablePureComponent { }; handleClick = e => { - if (e && (e.button !== 0 || e.ctrlKey || e.metaKey)) { + e.preventDefault(); + this.handleHotkeyOpen(e); + }; + + handleMouseUp = e => { + // Only handle clicks on the empty space above the content + + if (e.target !== e.currentTarget) { return; } - if (e) { - e.preventDefault(); - } - - this.handleHotkeyOpen(); - }; - - handlePrependAccountClick = e => { - this.handleAccountClick(e, false); - }; - - handleAccountClick = (e, proper = true) => { - if (e && (e.button !== 0 || e.ctrlKey || e.metaKey)) { - return; - } - - if (e) { - e.preventDefault(); - e.stopPropagation(); - } - - this._openProfile(proper); + this.handleClick(e); }; handleExpandedToggle = () => { @@ -287,7 +275,7 @@ class Status extends ImmutablePureComponent { this.props.onMention(this._properStatus().get('account')); }; - handleHotkeyOpen = () => { + handleHotkeyOpen = (e) => { if (this.props.onClick) { this.props.onClick(); return; @@ -300,7 +288,13 @@ class Status extends ImmutablePureComponent { return; } - history.push(`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`); + const path = `/@${status.getIn(['account', 'acct'])}/${status.get('id')}`; + + if (e?.button === 0 && !(e?.ctrlKey || e?.metaKey)) { + history.push(path); + } else if (e?.button === 1 || (e?.button === 0 && (e?.ctrlKey || e?.metaKey))) { + window.open(path, '_blank', 'noreferrer noopener'); + } }; handleHotkeyOpenProfile = () => { @@ -412,7 +406,7 @@ class Status extends ImmutablePureComponent { prepend = (
- }} /> + }} />
); @@ -550,20 +544,19 @@ class Status extends ImmutablePureComponent {
{(connectReply || connectUp || connectToRoot) &&
} - {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} -
- + {matchedFilters && } diff --git a/app/javascript/mastodon/components/status_content.jsx b/app/javascript/mastodon/components/status_content.jsx index 4950c896f9..fe485eb3ac 100644 --- a/app/javascript/mastodon/components/status_content.jsx +++ b/app/javascript/mastodon/components/status_content.jsx @@ -204,8 +204,8 @@ class StatusContent extends PureComponent { element = element.parentNode; } - if (deltaX + deltaY < 5 && e.button === 0 && this.props.onClick) { - this.props.onClick(); + if (deltaX + deltaY < 5 && (e.button === 0 || e.button === 1) && this.props.onClick) { + this.props.onClick(e); } this.startXY = null; diff --git a/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx b/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx index 65ea9b5d5e..ca0d1bc850 100644 --- a/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx +++ b/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx @@ -43,7 +43,7 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({ ); const handleMouseUp = useCallback>( - ({ clientX, clientY, target, button }) => { + ({ clientX, clientY, target, button, ctrlKey, metaKey }) => { const [startX, startY] = clickCoordinatesRef.current ?? [0, 0]; const [deltaX, deltaY] = [ Math.abs(clientX - startX), @@ -64,8 +64,14 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({ element = element.parentNode as HTMLDivElement | null; } - if (deltaX + deltaY < 5 && button === 0 && account) { - history.push(`/@${account.acct}/${statusId}`); + if (deltaX + deltaY < 5 && account) { + const path = `/@${account.acct}/${statusId}`; + + if (button === 0 && !(ctrlKey || metaKey)) { + history.push(path); + } else if (button === 1 || (button === 0 && (ctrlKey || metaKey))) { + window.open(path, '_blank', 'noreferrer noopener'); + } } clickCoordinatesRef.current = null;