diff options
author | 2021-05-02 09:49:27 +0800 | |
---|---|---|
committer | 2021-05-01 21:49:27 -0400 | |
commit | 1a81dc19ff452eb1b8e64dc1d077e3d92bbd7dda (patch) | |
tree | a6c5132f88e5049d8fa57e24ebaa7db7f3d1df33 | |
parent | c5c0cc3c65c503c7bdf15ca4736c4b1468223dfc (diff) | |
download | refined-github-1a81dc19ff452eb1b8e64dc1d077e3d92bbd7dda.tar.gz refined-github-1a81dc19ff452eb1b8e64dc1d077e3d92bbd7dda.tar.zst refined-github-1a81dc19ff452eb1b8e64dc1d077e3d92bbd7dda.zip |
Preserve URL hash in `faster-pr-diff-options` (#4304)
-rw-r--r-- | source/features/faster-pr-diff-options.tsx | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/source/features/faster-pr-diff-options.tsx b/source/features/faster-pr-diff-options.tsx index 287247ed..871d19a6 100644 --- a/source/features/faster-pr-diff-options.tsx +++ b/source/features/faster-pr-diff-options.tsx @@ -6,19 +6,19 @@ import {BookIcon, CheckIcon, DiffIcon} from '@primer/octicons-react'; import features from '.'; function createDiffStyleToggle(): DocumentFragment { - const parameters = new URLSearchParams(location.search); + const url = new URL(location.href); const isUnified = select.exists([ '[value="unified"][checked]', // Form in PR '.table-of-contents .selected[href$=unified]' // Link in single commit ]); function makeLink(type: string, icon: Element, selected: boolean): HTMLElement { - parameters.set('diff', type); + url.searchParams.set('diff', type); return ( <a className={`btn btn-sm BtnGroup-item tooltipped tooltipped-s ${selected ? 'selected' : ''}`} aria-label={`Show ${type} diffs`} - href={`?${String(parameters)}`} + href={url.href} > {icon} </a> @@ -34,18 +34,18 @@ function createDiffStyleToggle(): DocumentFragment { } function createWhitespaceButton(): HTMLElement { - const searchParameters = new URLSearchParams(location.search); - const isHidingWhitespace = searchParameters.get('w') === '1'; + const url = new URL(location.href); + const isHidingWhitespace = url.searchParams.get('w') === '1'; if (isHidingWhitespace) { - searchParameters.delete('w'); + url.searchParams.delete('w'); } else { - searchParameters.set('w', '1'); + url.searchParams.set('w', '1'); } return ( <a - href={`?${String(searchParameters)}`} + href={url.href} data-hotkey="d w" className={`btn btn-sm btn-outline tooltipped tooltipped-s ${isHidingWhitespace ? 'bg-gray-light text-gray-light color-text-tertiary' : ''}`} aria-label={`${isHidingWhitespace ? 'Show' : 'Hide'} whitespace in diffs`} |