diff options
author | 2022-10-07 00:14:30 +0700 | |
---|---|---|
committer | 2022-10-07 00:14:30 +0700 | |
commit | b681c734a35948991bda26760708ef57f85c902a (patch) | |
tree | 1102958093a98a3eb6021d447c7f69e98eaa3e47 | |
parent | 7d3d82c80ebd206b6c327aecd95ea5918be9e827 (diff) | |
parent | 34b273fb11130daf50421b3eecd707af57e4daac (diff) | |
download | refined-github-b681c734a35948991bda26760708ef57f85c902a.tar.gz refined-github-b681c734a35948991bda26760708ef57f85c902a.tar.zst refined-github-b681c734a35948991bda26760708ef57f85c902a.zip |
Merge remote-tracking branch 'origin' into esbuild-2
-rw-r--r-- | .github/workflows/test.yml | 4 | ||||
-rw-r--r-- | contributing.md | 2 | ||||
-rw-r--r-- | source/feature-manager.tsx | 6 | ||||
-rw-r--r-- | source/features/no-unnecessary-split-diff-view.css | 31 | ||||
-rw-r--r-- | source/features/no-unnecessary-split-diff-view.tsx | 65 |
5 files changed, 58 insertions, 50 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49f78306..bc5ff769 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,8 +71,8 @@ jobs: - uses: actions/upload-artifact@v2 if: matrix.os == 'ubuntu-latest' with: - name: refined-github - path: distribution + name: refined-github + path: distribution Safari: runs-on: macos-12 diff --git a/contributing.md b/contributing.md index 274fb607..5dd0f17a 100644 --- a/contributing.md +++ b/contributing.md @@ -133,7 +133,7 @@ Node.prototype.dispatchEvent = function (...a) { console.log(...a); // debugger; // Uncomment when necessary d.apply(this, a); -} +}; ``` <img width="379" alt="screen" src="https://user-images.githubusercontent.com/1402241/79168882-406ea100-7deb-11ea-9e9c-ad657202422f.png"> diff --git a/source/feature-manager.tsx b/source/feature-manager.tsx index 3cede3c3..9653c1b3 100644 --- a/source/feature-manager.tsx +++ b/source/feature-manager.tsx @@ -251,6 +251,10 @@ const add = async (url: string, ...loaders: FeatureLoader[]): Promise<void> => { additionalListeners = [], } = loader; + if (include?.length === 0) { + throw new Error(`${id}: \`include\` cannot be an empty array, it means "run nowhere"`); + } + // Register feature shortcuts for (const [hotkey, description] of Object.entries(shortcuts)) { shortcutMap.set(hotkey, description); @@ -279,7 +283,7 @@ const add = async (url: string, ...loaders: FeatureLoader[]): Promise<void> => { } }; -const addCssFeature = async (url: string, include: BooleanFunction[] | undefined): Promise<void> => { +const addCssFeature = async (url: string, include?: BooleanFunction[]): Promise<void> => { const id = getFeatureID(url); void add(id, { include, diff --git a/source/features/no-unnecessary-split-diff-view.css b/source/features/no-unnecessary-split-diff-view.css index ed7b4f77..5f195b27 100644 --- a/source/features/no-unnecessary-split-diff-view.css +++ b/source/features/no-unnecessary-split-diff-view.css @@ -1,13 +1,30 @@ -[data-rgh-hide-empty-split-diff-side] { +/* The selector looks for diff tables WITHOUT changes on the left XOR on the right */ +/* Instead of duplicating this selector for each rule, we set a variable and pick it up where needed */ +.rgh-no-unnecessary-split-diff-view .js-diff-table:not( +:has([data-split-side='left']:is(.blob-code-addition, .blob-code-deletion)) +) { + --rgh-only-additions: none; table-layout: auto !important; } -[data-rgh-hide-empty-split-diff-side='left'] :is([data-hunk], .blob-expanded) td:nth-child(2), -[data-rgh-hide-empty-split-diff-side='right'] :is([data-hunk], .blob-expanded) td:nth-child(4) { - display: none !important; - width: 0 !important; +.rgh-no-unnecessary-split-diff-view .js-diff-table:not( +:has([data-split-side='right']:is(.blob-code-addition, .blob-code-deletion)) +) { + --rgh-only-deletions: none; + table-layout: auto !important; +} + +/* Only additions: Hide the left side */ +.rgh-no-unnecessary-split-diff-view :is([data-hunk], .blob-expanded) td:nth-child(2) { + display: var(--rgh-only-additions, table-cell) !important; +} + +/* Only deletions: Hide the right side */ +.rgh-no-unnecessary-split-diff-view :is([data-hunk], .blob-expanded) td:nth-child(4) { + display: var(--rgh-only-deletions, table-cell) !important; } -[data-rgh-hide-empty-split-diff-side] :is(.inline-comments, .js-inline-annotations) .empty-cell:not(.blob-num) { - display: none !important; +/* Any applicable situation: Re-align annotations, which are always on the left */ +.rgh-no-unnecessary-split-diff-view :is(.inline-comments, .js-inline-annotations) td:nth-child(2) { + display: var(--rgh-only-additions, var(--rgh-only-deletions, table-cell)) !important; } diff --git a/source/features/no-unnecessary-split-diff-view.tsx b/source/features/no-unnecessary-split-diff-view.tsx index 4af30271..6cc667df 100644 --- a/source/features/no-unnecessary-split-diff-view.tsx +++ b/source/features/no-unnecessary-split-diff-view.tsx @@ -1,43 +1,30 @@ import './no-unnecessary-split-diff-view.css'; -import select from 'select-dom'; import * as pageDetect from 'github-url-detection'; import features from '../feature-manager'; -import {onDiffFileLoad} from '../github-events/on-fragment-load'; - -function isUnifiedDiff(): boolean { - return select.exists([ - '[value="unified"][checked]', // Form in PR - '.table-of-contents .selected[href*="diff=unified"]', // Link in single commit - ]); -} - -function init(): void { - for (const diffTable of select.all('.js-diff-table:not(.rgh-no-unnecessary-split-diff-view-visited)')) { - diffTable.classList.add('rgh-no-unnecessary-split-diff-view-visited'); - for (const side of ['left', 'right']) { - if (!select.exists(`[data-split-side="${side}"]:is(.blob-code-addition, .blob-code-deletion)`, diffTable)) { - diffTable.setAttribute('data-rgh-hide-empty-split-diff-side', side); - break; - } - } - } -} - -void features.add(import.meta.url, { - asLongAs: [ - // Make sure the class names we need exist on the page #4483 - () => select.exists('.js-diff-table :is([data-split-side="left"], [data-split-side="right"]):is(.blob-code-addition, .blob-code-deletion)'), - ], - include: [ - pageDetect.hasFiles, - ], - exclude: [ - isUnifiedDiff, - ], - additionalListeners: [ - onDiffFileLoad, - ], - deduplicate: 'has-rgh-inner', - init, -}); + +void features.addCssFeature(import.meta.url, [ + pageDetect.hasFiles, +]); + +/* + +## Test URLs + +### PR files + +https://github.com/refined-github/sandbox/pull/50/files?diff=split + +### PR files with annotations + +https://github.com/fregante/sandbox/pull/30/files + +### Compare page + +https://github.com/refined-github/sandbox/compare/no-unnecessary-split-diff-view?expand=1&diff=split + +### Single commit + +https://github.com/refined-github/sandbox/commit/c28cc8e5271452b5b4c347d46a63f717c29417d6?diff=split + +*/ |