-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add 3 file-finder-related features
#2825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fregante
merged 34 commits into
refined-github:master
from
danedavid:enhancements/file-finder-improvements-2467
Mar 7, 2020
Merged
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 8a15759
Preserve search term in file finder
danedavid 1d9e341
Persist buffer to local storage. Refactor out common functions.
danedavid 1a18042
Fix issue with keydown not ignored in TEXTAREA nodes
danedavid 17716b0
Fix lint issues
danedavid bfec80d
Replace master in file finder link with o/p of getDefaultBranch()
danedavid f39a921
Append hidden anchor tag to PJAX container. Restrict feature to issue…
danedavid a03a6ec
ESLint fixes for repo-wide-file-finder
danedavid ef35c2b
Add file-finder-buffer as a separate feature
danedavid 9c807cc
Manually trigger event after setting input value to buffer
danedavid e088310
Rewrite preserve-file-finder to as separate feature
danedavid 8c702d1
Remove unnecessary file
danedavid 8fa4f0f
Remove unused import
danedavid 99e3f23
Remove unnecessary variables, excludes & deinit from repo-wide-file-f…
danedavid d441060
Remove keydown handler in favor of beforeunload & pjax:start event ha…
danedavid 9d204e2
Remove keydown handler in favor of hidden input in file-finder-buffer
danedavid cf1d53a
Code improvements after review
danedavid 5d6dbe1
Replace visuallyhidden with GH's inbuilt sr-only class
danedavid 4fb111e
Inline select call
danedavid 7b4ff75
Remove and create hidden input on pjax start and complete every time.…
danedavid c8f298b
Fix indentation
danedavid 5b04f27
Remove unwanted constant
danedavid b41bb18
Replace unnecessarily long selector string
danedavid f2ac4dc
Replace removeChild() with remove()
danedavid cdcdb28
Remove unwanted type annotations
danedavid 688832f
Remove await before adding event listeners
danedavid 5652e7b
Lint `preserve-file-finder-term`
fregante c0f2182
Use `history.state` in `preserve-file-finder-term`
fregante c5ba97d
Lint `file-finder-buffer`
fregante d1ca1ac
Make buffer visible
fregante e9e97dc
Lint `repo-wide-file-finder`
fregante d99928b
Preserve cursor/selection when switching field in `file-finder-buffer`
fregante 2d4be60
List the features in readme with screenshot links
danedavid 3a7c6b1
Update descriptions
fregante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }); | ||
danedavid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()}`} | ||
| /> | ||
| ); | ||
danedavid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| 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 | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.