Skip to content

Commit

Permalink
Don't collapse-markdown-sections when clicking links (#4127)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheap-glitch committed Mar 19, 2021
1 parent 1243d38 commit 4be7b91
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion source/features/collapse-markdown-sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import * as pageDetect from 'github-url-detection';

import features from '.';

function onHeadingClick({delegateTarget: sectionHeading}: delegate.Event<MouseEvent, HTMLElement>): void {
function onHeadingClick(event: delegate.Event<MouseEvent, HTMLElement>): void {
// Don't toggle the section if the title text is being selected instead of clicked
if (document.getSelection()?.type === 'Range') {
return;
}

// Don't toggle the section if a link in the heading is clicked (either the content or the anchor)
if ((event.target as HTMLElement).closest('a')) {
return;
}

const sectionHeading = event.delegateTarget;
const isSectionHidden = sectionHeading.classList.toggle('rgh-markdown-section-collapsed');
let element = sectionHeading.tagName === 'H1' ?
sectionHeading.parentElement!.firstElementChild as HTMLElement :
Expand Down

0 comments on commit 4be7b91

Please sign in to comment.