diff options
author | 2023-07-05 13:48:17 +0100 | |
---|---|---|
committer | 2023-07-05 14:48:17 +0200 | |
commit | f9366820815cc0305efcb83de66fe1fe999d1a7b (patch) | |
tree | b5b63462eef565fb39aaa939a3b7ca25b0a364f0 /source/features/easy-toggle-commit-messages.tsx | |
parent | 30c9b8bd8098e85b429070b02d04079ed12cbf30 (diff) | |
download | refined-github-f9366820815cc0305efcb83de66fe1fe999d1a7b.tar.gz refined-github-f9366820815cc0305efcb83de66fe1fe999d1a7b.tar.zst refined-github-f9366820815cc0305efcb83de66fe1fe999d1a7b.zip |
Prevent `easy-toggle-commit-messages` when selecting text (#6751)
Diffstat (limited to '')
-rw-r--r-- | source/features/easy-toggle-commit-messages.tsx | 32 |
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. + +*/ |