-
Notifications
You must be signed in to change notification settings - Fork 7
Add Ctrl+A / Cmd+A keybind to select all files in current file set #758
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
Open
Copilot
wants to merge
23
commits into
main
Choose a base branch
from
copilot/add-select-all-functionality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c36c658
Initial plan
Copilot ad6787b
Add Ctrl+A (Select All) keybind to DirectoryTree component
Copilot 3a89e6c
Use last-touched folder's file set for Ctrl+A select all if folder is…
Copilot 1e90e18
Improve readability of folder path extraction and strengthen test ass…
Copilot 31aaa6c
Track lastTouchedFolder in Redux state for cleaner Select All behavior
Copilot 803202e
Rename folderPath to rawFolderPath, add length guard for hierarchy/fo…
Copilot 0805452
Extract useSelectAll hook, set lastTouchedFolder on folder open, remo…
Copilot e39f745
Fix code review: remove double negation, use positive if-branch in us…
Copilot 670f39f
Simplify lastTouchedFolder tracking
SeanDuHare 57bc877
Include file selection in last touched consideration
SeanDuHare 9d4f3ec
Remove unused import
SeanDuHare 35e9f6a
Add unit tests for reducer logic
SeanDuHare 4cffb7e
Remove tracking last opened folder
SeanDuHare 1fd853e
Change file type to ts from tsx
SeanDuHare 0f39c5a
Update comment for file filter changes
SeanDuHare 9ce8bfb
Remove non-null assertion
SeanDuHare beb8b73
Merge branch 'main' into copilot/add-select-all-functionality
SeanDuHare eb4c86f
Fix import order
SeanDuHare 859ec42
Merge branch 'main' into copilot/add-select-all-functionality
SeanDuHare d37d4b8
Merge branch 'main' into copilot/add-select-all-functionality
SeanDuHare 04b3835
Focus minimum in selection for existing file selections; ignore serve…
SeanDuHare 5c82664
Show loading spinner in aggregate between selections
SeanDuHare 1819ae7
Merge branch 'main' into copilot/add-select-all-functionality
SeanDuHare 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
114 changes: 114 additions & 0 deletions
114
packages/core/components/DirectoryTree/useSelectAll.tsx
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,114 @@ | ||
| import * as React from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
|
|
||
| import FileFilter, { FilterType } from "../../entity/FileFilter"; | ||
| import FileSet from "../../entity/FileSet"; | ||
| import NumericRange from "../../entity/NumericRange"; | ||
| import { interaction, selection } from "../../state"; | ||
|
|
||
| enum KeyboardCode { | ||
|
SeanDuHare marked this conversation as resolved.
Outdated
|
||
| A = "a", | ||
| } | ||
|
|
||
| /** | ||
| * React hook that registers a Ctrl+A / Cmd+A keyboard shortcut to select all | ||
| * files within the last-opened folder. | ||
| * | ||
| * Behavior: | ||
| * - If there is no annotation hierarchy (flat list), selects all files in the | ||
| * root file set. | ||
| * - If there is an annotation hierarchy, selects all files in the folder the | ||
| * user most recently opened (`lastTouchedFolder`) — but only if that folder | ||
| * is still present in `openFileFolders`. Does nothing otherwise. | ||
| * - No-ops while a modal overlay is visible (consistent with arrow-key behavior). | ||
| */ | ||
| export default function useSelectAll(): void { | ||
| const dispatch = useDispatch(); | ||
| const fileService = useSelector(interaction.selectors.getFileService); | ||
| const globalFilters = useSelector(selection.selectors.getFileFilters); | ||
| const sortColumn = useSelector(selection.selectors.getSortColumn); | ||
| const visibleModal = useSelector(interaction.selectors.getVisibleModal); | ||
| const annotationHierarchy = useSelector(selection.selectors.getAnnotationHierarchy); | ||
| const lastTouchedFolder = useSelector(selection.selectors.getLastTouchedFolder); | ||
| const openFileFolders = useSelector(selection.selectors.getOpenFileFolders); | ||
|
|
||
| // Root file set (used for flat-list case) | ||
| const rootFileSet = React.useMemo( | ||
| () => | ||
| new FileSet({ | ||
| fileService, | ||
| filters: globalFilters, | ||
| sort: sortColumn, | ||
| }), | ||
| [fileService, globalFilters, sortColumn] | ||
| ); | ||
|
|
||
| React.useEffect(() => { | ||
| const onSelectAllKeyDown = async (event: KeyboardEvent) => { | ||
| if (visibleModal) return; | ||
| if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === KeyboardCode.A) { | ||
| event.preventDefault(); | ||
|
|
||
| let targetFileSet: FileSet; | ||
|
|
||
| if (annotationHierarchy.length === 0) { | ||
| // Flat list — no folder concept, always select all in root | ||
| targetFileSet = rootFileSet; | ||
| } else if ( | ||
| lastTouchedFolder && | ||
| lastTouchedFolder.fileFolder.length === annotationHierarchy.length && | ||
| openFileFolders.some((f) => f.equals(lastTouchedFolder)) | ||
| ) { | ||
| // Rebuild the FileSet for the last-touched folder by combining | ||
| // the hierarchy filters (one per level from the folder path) with | ||
| // any non-hierarchy global filters the user may have applied. | ||
| const hierarchyFilters = annotationHierarchy.map( | ||
| (annotationName, idx) => | ||
| new FileFilter( | ||
| annotationName, | ||
| lastTouchedFolder.fileFolder[idx], | ||
| FilterType.DEFAULT | ||
| ) | ||
| ); | ||
| const nonHierarchyFilters = globalFilters.filter( | ||
| (f) => | ||
| !(annotationHierarchy.includes(f.name) && f.type === FilterType.DEFAULT) | ||
| ); | ||
| targetFileSet = new FileSet({ | ||
| fileService, | ||
| filters: [...hierarchyFilters, ...nonHierarchyFilters], | ||
| sort: sortColumn, | ||
| }); | ||
| } else { | ||
| // No last-touched folder or the folder has since been closed — do nothing | ||
| return; | ||
| } | ||
|
|
||
| const totalCount = await targetFileSet.fetchTotalCount(); | ||
| if (totalCount > 0) { | ||
| dispatch( | ||
| selection.actions.selectFile({ | ||
| fileSet: targetFileSet, | ||
| selection: new NumericRange(0, totalCount - 1), | ||
| sortOrder: 0, | ||
| updateExistingSelection: false, | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| window.addEventListener("keydown", onSelectAllKeyDown, true); | ||
| return () => window.removeEventListener("keydown", onSelectAllKeyDown, true); | ||
| }, [ | ||
| annotationHierarchy, | ||
| dispatch, | ||
| fileService, | ||
| globalFilters, | ||
| lastTouchedFolder, | ||
| openFileFolders, | ||
| rootFileSet, | ||
| sortColumn, | ||
| visibleModal, | ||
| ]); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.