Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
46f9b54
Add hidden file finder button to all pages to enable 't' shortcut
danedavid Feb 21, 2020
8a15759
Preserve search term in file finder
danedavid Feb 21, 2020
1d9e341
Persist buffer to local storage. Refactor out common functions.
danedavid Feb 22, 2020
1a18042
Fix issue with keydown not ignored in TEXTAREA nodes
danedavid Feb 22, 2020
17716b0
Fix lint issues
danedavid Feb 22, 2020
bfec80d
Replace master in file finder link with o/p of getDefaultBranch()
danedavid Feb 22, 2020
f39a921
Append hidden anchor tag to PJAX container. Restrict feature to issue…
danedavid Feb 23, 2020
a03a6ec
ESLint fixes for repo-wide-file-finder
danedavid Feb 23, 2020
ef35c2b
Add file-finder-buffer as a separate feature
danedavid Feb 23, 2020
9c807cc
Manually trigger event after setting input value to buffer
danedavid Feb 23, 2020
e088310
Rewrite preserve-file-finder to as separate feature
danedavid Feb 23, 2020
8c702d1
Remove unnecessary file
danedavid Feb 23, 2020
8fa4f0f
Remove unused import
danedavid Feb 23, 2020
99e3f23
Remove unnecessary variables, excludes & deinit from repo-wide-file-f…
danedavid Feb 24, 2020
d441060
Remove keydown handler in favor of beforeunload & pjax:start event ha…
danedavid Feb 24, 2020
9d204e2
Remove keydown handler in favor of hidden input in file-finder-buffer
danedavid Feb 24, 2020
cf1d53a
Code improvements after review
danedavid Feb 24, 2020
5d6dbe1
Replace visuallyhidden with GH's inbuilt sr-only class
danedavid Feb 24, 2020
4fb111e
Inline select call
danedavid Feb 24, 2020
7b4ff75
Remove and create hidden input on pjax start and complete every time.…
danedavid Feb 24, 2020
c8f298b
Fix indentation
danedavid Feb 24, 2020
5b04f27
Remove unwanted constant
danedavid Feb 24, 2020
b41bb18
Replace unnecessarily long selector string
danedavid Feb 24, 2020
f2ac4dc
Replace removeChild() with remove()
danedavid Feb 24, 2020
cdcdb28
Remove unwanted type annotations
danedavid Feb 24, 2020
688832f
Remove await before adding event listeners
danedavid Feb 25, 2020
5652e7b
Lint `preserve-file-finder-term`
fregante Feb 28, 2020
c0f2182
Use `history.state` in `preserve-file-finder-term`
fregante Feb 28, 2020
c5ba97d
Lint `file-finder-buffer`
fregante Feb 28, 2020
d1ca1ac
Make buffer visible
fregante Feb 28, 2020
e9e97dc
Lint `repo-wide-file-finder`
fregante Feb 28, 2020
d99928b
Preserve cursor/selection when switching field in `file-finder-buffer`
fregante Mar 5, 2020
2d4be60
List the features in readme with screenshot links
danedavid Mar 7, 2020
3a7c6b1
Update descriptions
fregante Mar 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ Thanks for contributing! 🦋🙌
- [](# "reload-failed-proxied-images") [Retries downloading images that failed downloading due to GitHub limited proxying.](https://user-images.githubusercontent.com/14858959/64068746-21991100-cc45-11e9-844e-827f5ac9b51e.png)
- [](# "forked-to") [Adds a shortcut to your forks next to the `Fork` button on the current repo.](https://user-images.githubusercontent.com/55841/64077281-17bbf000-cccf-11e9-9123-092063f65357.png)
- [](# "repo-age") [Adds the age of the repository to the statistics bar.](https://user-images.githubusercontent.com/3848317/69494069-7d2b1180-0eb7-11ea-9aa1-d4194e566340.png)
- [](# "repo-wide-file-finder") Enables the the File Finder keyboard shortcut (<kbd>t</kbd>) on Issues and Pull Request pages as well.
- [](# "file-finder-buffer") [Lets you start typing your search immediately after invoking the File Finder (<kbd>t</kbd>), instead of having you wait for it to load first.](https://user-images.githubusercontent.com/1402241/75542106-1c811700-5a5a-11ea-8aa5-bea0472c59e2.gif)
- [](# "preserve-file-finder-term") Preserves the search terms when navigating back and forth between the File Finder and the files.

<!-- Refer to style guide above. Keep this message between sections. -->

Expand Down
3 changes: 3 additions & 0 deletions source/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ import './features/quick-mention';
import './features/extend-discussion-status-filters';
import './features/expand-all-hidden-comments';
import './features/bugs-tab';
import './features/repo-wide-file-finder';
import './features/preserve-file-finder-term';
import './features/file-finder-buffer';

// Add global for easier debugging
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
57 changes: 57 additions & 0 deletions source/features/file-finder-buffer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import features from '../libs/features';

const getBufferField = onetime((): HTMLInputElement => (
<input
type="text"
className="form-control tree-finder-input p-0 ml-1 border-0"
style={{marginTop: '-0.19em'}}
/> as unknown as HTMLInputElement
));

function pjaxStartHandler(event: CustomEvent): void {
const destinationURL = event.detail?.url || '';
if (destinationURL.split('/')[5] !== 'find') {
return;
}

const bufferField = getBufferField();
bufferField.value = '';

const repoName = select('.pagehead h1 strong')!;
repoName.classList.remove('mr-2');
repoName.after(
<span className="path-divider flex-self-stretch">/</span>,
<span className="flex-self-stretch mr-2">{bufferField}</span>
);
bufferField.focus();
select('.pagehead-actions')!.remove();
}

function pjaxCompleteHandler(): void {
const fileFinderInput = select<HTMLInputElement>('#tree-finder-field');
if (fileFinderInput) {
const bufferField = getBufferField();
fileFinderInput.value = bufferField.value;
fileFinderInput.selectionStart = bufferField.selectionStart;
fileFinderInput.selectionEnd = bufferField.selectionEnd;
fileFinderInput.dispatchEvent(new Event('input')); // Trigger search
}
}

function init(): void {
window.addEventListener('pjax:start', pjaxStartHandler);
window.addEventListener('pjax:complete', pjaxCompleteHandler);
}

features.add({
id: __featureName__,
description: 'Lets you start typing your search immediately after invoking the File Finder (`t`), instead of having you wait for it to load first.',
screenshot: 'https://user-images.githubusercontent.com/1402241/75542106-1c811700-5a5a-11ea-8aa5-bea0472c59e2.gif',
include: [
features.isRepo
],
init
});
47 changes: 47 additions & 0 deletions source/features/preserve-file-finder-term.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import select from 'select-dom';
import elementReady from 'element-ready';
import features from '../libs/features';

function unloadHandler(): void {
const inputElement = select<HTMLInputElement>('#tree-finder-field');
if (inputElement) {
history.replaceState({
...history.state,
rghFileFinderTerm: inputElement.value
}, document.title);
}
}

// Set the input field value & trigger event
async function setValueInField(): Promise<void> {
const preservedValue = history.state.rghFileFinderTerm;
const inputElement = select<HTMLInputElement>('#tree-finder-field');
if (inputElement && !inputElement.value && preservedValue) {
await elementReady('.js-tree-browser-results > li', {stopOnDomReady: false}); // For search to work
inputElement.value = preservedValue;
inputElement.dispatchEvent(new Event('input')); // Trigger search
}
}

function init(): void {
setValueInField();
window.addEventListener('beforeunload', unloadHandler);
window.addEventListener('pjax:start', unloadHandler);
}

function deinit(): void {
window.removeEventListener('beforeunload', unloadHandler);
window.removeEventListener('pjax:start', unloadHandler);
}

features.add({
id: __featureName__,
description: 'Preserves the search terms when navigating back and forth between the File Finder and the files.',
screenshot: false,
include: [
features.isFileFinder
],
load: features.onAjaxedPages,
init,
deinit
});
31 changes: 31 additions & 0 deletions source/features/repo-wide-file-finder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {getRepoURL} from '../libs/utils';
import getDefaultBranch from '../libs/get-default-branch';

async function init(): Promise<void> {
if (!select.exists('[data-hotkey="t"]')) {
document.body.append(
<a
hidden
data-hotkey="t"
data-pjax="true"
href={`/${getRepoURL()}/find/${await getDefaultBranch()}`}
/>
);
}
}

features.add({
id: __featureName__,
description: 'Enables the the File Finder keyboard shortcut (`t`) on Issues and Pull Request pages as well.',
screenshot: false,
include: [
features.isRepoDiscussionList,
features.isPR,
features.isIssue
],
load: features.onAjaxedPages,
init
});
1 change: 1 addition & 0 deletions source/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface GlobalEventHandlersEventMap {
'rgh:view-markdown-rendered': CustomEvent;
'filterable:change': CustomEvent;
'page:loaded': CustomEvent;
'pjax:start': CustomEvent;
}

declare namespace JSX {
Expand Down
6 changes: 6 additions & 0 deletions source/libs/page-detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ export const _isSingleFile = [
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css',
'https://github.com/sindresorhus/refined-github/blob/master/edit.txt'
];

export const isFileFinder = (): boolean => /^find\//.test(getRepoPath()!);
export const _isFileFinder = [
'https://github.com/sindresorhus/refined-github/find/master'
];

export const isSingleGist = (): boolean => isGist() && /^\/(gist\/)?[^/]+\/[0-9a-f]{32}$/.test(location.pathname);
export const _isSingleGist = [
'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064'
Expand Down