Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/resources/src/mediawiki.diff/diff.js b/resources/src/mediawiki.diff/diff.js
index 500e0a5bd5f..093a8252e6c 100644
--- a/resources/src/mediawiki.diff/diff.js
+++ b/resources/src/mediawiki.diff/diff.js
@@ -6,6 +6,8 @@ const inlineFormatToggle = require( './inlineFormatToggle.js' );
( function () {
$( () => {
/**
+ * Get the diff side of the given node, or undefined if the node is outside the diff.
+ *
* @param {Node} node
* @return {string|undefined}
* @ignore
@@ -34,10 +36,15 @@ const inlineFormatToggle = require( './inlineFormatToggle.js' );
* @ignore
*/
function setSideLock( side ) {
- $( '.diff' ).attr( 'data-selected-side', side );
+ $( '.diff' ).attr( 'data-selected-side', side || null );
}
/**
+ * When the user clicks somewhere, check whether the node belongs to the diff. If it does, lock the
+ * selection to that side of the diff. If it doesn't, unlock selection.
+ * Also, if selection is already locked and the user clicks outside of the currently-locked column,
+ * clear the selection to prevent annoying glitches (e.g. when shift-click-selecting; see also T292207).
+ *
* @param {MouseEvent} e
* @ignore
*/
@@ -46,24 +53,38 @@ const inlineFormatToggle = require( './inlineFormatToggle.js' );
// Right click.
return;
}
- const clickSide = getNodeSide( e.target );
- if ( getCurrentlyLockedSide() !== clickSide ) {
+ const clickSide = getNodeSide( e.target ),
+ lockedSide = getCurrentlyLockedSide();
+ if ( lockedSide && lockedSide !== clickSide ) {
document.getSelection().removeAllRanges();
}
setSideLock( clickSide );
}
+ /**
+ * When a new selection is started, see if the anchor node belongs to the diff, and if so lock the selection
+ * to that side. If the anchor is outside the diff, clear any previously set locking.
+ *
+ * @ignore
+ */
function selectionHandler() {
- const textNode = document.getSelection().anchorNode;
+ // Different browsers behave differently when handling the `selectionstart` event. For example, in
+ // Chrome 135, the `getSelection()` call would not return the currently-starting selection, but some
+ // random outdated value from a previous selection, or just nothing. In Firefox 137, instead, it sees
+ // the current selection. Other browsers are untested. Enqueue the processing in a timeout so that
+ // hopefully all browsers see the expected value.
+ setTimeout( () => {
+ const anchorNode = document.getSelection().anchorNode;
- if ( !textNode ) {
- return;
- }
+ if ( !anchorNode ) {
+ return;
+ }
- setSideLock( getNodeSide( textNode ) );
+ setSideLock( getNodeSide( anchorNode ) );
+ }, 0 );
}
- $( document ).on( 'selectionchange', selectionHandler );
+ $( document ).on( 'selectstart', selectionHandler );
$( document ).on( 'mousedown', maybeClearSelectProtection );
$( document ).on(

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:31 AM (8 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227403
Default Alt Text
(2 KB)

Event Timeline