diff options
Diffstat (limited to 'source/features/easy-toggle-files.tsx')
-rw-r--r-- | source/features/easy-toggle-files.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/features/easy-toggle-files.tsx b/source/features/easy-toggle-files.tsx index db6d0381..74ed87e2 100644 --- a/source/features/easy-toggle-files.tsx +++ b/source/features/easy-toggle-files.tsx @@ -2,7 +2,9 @@ import {$} from 'select-dom'; import delegate, {DelegateEvent} from 'delegate-it'; import * as pageDetect from 'github-url-detection'; +import {codeSearchHeader} from '../github-helpers/selectors.js'; import features from '../feature-manager.js'; +import {isHasSelectorSupported} from '../helpers/select-has.js'; function toggleFile(event: DelegateEvent<MouseEvent>): void { const elementClicked = event.target as HTMLElement; @@ -15,14 +17,46 @@ function toggleFile(event: DelegateEvent<MouseEvent>): void { } } +function toggleCodeSearchFile(event: DelegateEvent<MouseEvent>): void { + const elementClicked = event.target as HTMLElement; + const headerBar = event.delegateTarget; + const toggle = $(':scope > button', headerBar)!; + + // The clicked element is either the bar itself or one of its children excluding the button + if (elementClicked === headerBar || (elementClicked.parentElement === headerBar && elementClicked !== toggle)) { + toggle.dispatchEvent(new MouseEvent('click', {bubbles: true, altKey: event.altKey})); + } +} + function init(signal: AbortSignal): void { delegate('.file-header', 'click', toggleFile, {signal}); } +function initSearchPage(signal: AbortSignal): void { + delegate(codeSearchHeader, 'click', toggleCodeSearchFile, {signal}); +} + void features.add(import.meta.url, { include: [ pageDetect.hasFiles, pageDetect.isGistRevision, ], init, +}, { + asLongAs: [ + isHasSelectorSupported, + ], + include: [ + pageDetect.isGlobalSearchResults, + ], + init: initSearchPage, }); + +/* + +## Test URLs + +- Pull Request: https://github.com/refined-github/refined-github/pull/7036/files +- Code Search: https://github.com/search?q=repo%3Arefined-github%2Frefined-github%20easy&type=code + +*/ |