summaryrefslogtreecommitdiff
path: root/source/features/easy-toggle-commit-messages.tsx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/features/easy-toggle-commit-messages.tsx32
1 files changed, 27 insertions, 5 deletions
diff --git a/source/features/easy-toggle-commit-messages.tsx b/source/features/easy-toggle-commit-messages.tsx
index 2197439c..8d028106 100644
--- a/source/features/easy-toggle-commit-messages.tsx
+++ b/source/features/easy-toggle-commit-messages.tsx
@@ -5,13 +5,20 @@ import delegate, {DelegateEvent} from 'delegate-it';
import features from '../feature-manager.js';
function toggleCommitMessage(event: DelegateEvent<MouseEvent>): void {
+ // The clicked element is a button, a link or a popup ("Verified" badge, CI details, etc.)
const elementClicked = event.target as HTMLElement;
- // The clicked element is not a button, a link or a popup ("Verified" badge, CI details, etc.)
- if (!elementClicked.closest('a, button, clipboard-copy, details')) {
- select('.ellipsis-expander', event.delegateTarget)?.dispatchEvent(
- new MouseEvent('click', {bubbles: true, altKey: event.altKey}),
- );
+ if (elementClicked.closest('a, button, clipboard-copy, details')) {
+ return;
}
+
+ // There is text selection
+ if (window.getSelection()?.toString().length !== 0) {
+ return;
+ }
+
+ select('.ellipsis-expander', event.delegateTarget)?.dispatchEvent(
+ new MouseEvent('click', {bubbles: true, altKey: event.altKey}),
+ );
}
const commitMessagesSelector = [
@@ -32,3 +39,18 @@ void features.add(import.meta.url, {
],
init,
});
+
+/*
+
+Test URLs:
+
+https://github.com/refined-github/sandbox/tree/254a81ef488dcb3866cf8a4cacde501d9faaa588
+
+How to test:
+
+1. Ensure that clicking the ellipsis can still expand/elide the commit message correctly.
+2. Ensure that clicking next to the ellipsis can also expand/elide the commit message.
+3. Ensure that clicking on the expanded commit message can elide it.
+4. Ensure that selecting texts in the expanded commit message would not elide it.
+
+*/