Don't clear target comment highlight when Ctrl-clicking

It annoys me when Ctrl-click clears it but middle-click does not.

Change-Id: I8636140df25d44ac79cb2bc0d1aebecc62c4db5d
This commit is contained in:
Bartosz Dziewoński 2022-02-07 00:38:53 +01:00
parent 37c09cd3ac
commit 909f1383d4
3 changed files with 15 additions and 4 deletions

View file

@ -136,7 +136,7 @@ ReplyLinksController.prototype.isActivationEvent = function ( e ) {
// Only handle keypresses on the "Enter" or "Space" keys
return false;
}
if ( e.type === 'click' && ( e.which !== OO.ui.MouseButtons.LEFT || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) ) {
if ( e.type === 'click' && !utils.isUnmodifiedLeftClick( e ) ) {
// Only handle unmodified left clicks
return false;
}

View file

@ -287,7 +287,7 @@ function initTopicSubscriptions( $container ) {
// Only handle keypresses on the "Enter" or "Space" keys
return;
}
if ( e.type === 'click' && ( e.which !== OO.ui.MouseButtons.LEFT || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) ) {
if ( e.type === 'click' && !utils.isUnmodifiedLeftClick( e ) ) {
// Only handle unmodified left clicks
return;
}
@ -888,7 +888,7 @@ function init( $container, state ) {
} );
// eslint-disable-next-line no-jquery/no-global-selector
$( 'body' ).on( 'click', function ( e ) {
if ( e.which === OO.ui.MouseButtons.LEFT ) {
if ( utils.isUnmodifiedLeftClick( e ) ) {
clearHighlightTargetComment( parser );
}
} );

View file

@ -601,6 +601,16 @@ function compareRangesAlmostEqualBoundaries( a, b, boundary ) {
return !foundContent;
}
/**
* Check whether a jQuery event represents a plain left click, without any modifiers
*
* @param {jQuery.Event} e
* @return {boolean} Whether it was an unmodified left click
*/
function isUnmodifiedLeftClick( e ) {
return e.which === OO.ui.MouseButtons.LEFT && !( e.shiftKey || e.altKey || e.ctrlKey || e.metaKey );
}
module.exports = {
NEW_TOPIC_COMMENT_ID: NEW_TOPIC_COMMENT_ID,
isBlockElement: isBlockElement,
@ -619,5 +629,6 @@ module.exports = {
getTitleFromUrl: getTitleFromUrl,
linearWalk: linearWalk,
linearWalkBackwards: linearWalkBackwards,
compareRanges: compareRanges
compareRanges: compareRanges,
isUnmodifiedLeftClick: isUnmodifiedLeftClick
};