Skip to content

File selection of disabled entries possible with space #5934

Closed

Description

@biolauri

Description

I have a long-running pre-commit hook. After hitting commit, the checkboxes for file selection are getting disabled immediately and any clicking on these checkboxes are prevented (everything fine here).
However, I can still mark a checkbox by hitting space on a highlighted entry/file, which is quite misleading. Luckily, this has no impact on the commit itself (nor the pre-commit hook), so it's only a bug in convenience which might be confusing for users, but without any impact on functionality.

Version

  • GitHub Desktop: 1.4.2
  • Operating system: Microsoft Windows [Version 10.0.17134.345]

Steps to Reproduce

  1. Add a long-running pre-commit hook; for testing, try sleep 30s
  2. Edit some files (at least 2)
  3. Select one file and commit it
  4. While the pre-commit hook runs, select the other file and hit space. You can also deselect the currently committed file

Expected Behavior

Hitting space doesn't do anything until the commit has been done.

Actual Behavior

Hitting space selects/deselects files, although they're disabled.

Activity

  1. shiftkey commented on Oct 18, 2018

    @shiftkey
    Member

    @biolauri thanks for the report!

    However, I can still mark a checkbox by hitting space on a highlighted entry/file, which is quite misleading.

    Yep, that's definitely a minor UX bug we should address. I think the Enter key also has the same issue.

    I put together a rough patch to address this below, for someone to take further:

    diff --git a/app/src/ui/changes/changes-list.tsx b/app/src/ui/changes/changes-list.tsx
    index df84b8514..b188e8df3 100644
    --- a/app/src/ui/changes/changes-list.tsx
    +++ b/app/src/ui/changes/changes-list.tsx
    @@ -368,6 +368,18 @@ export class ChangesList extends React.Component<
         showContextualMenu(items)
       }
     
    +  private onRowKeyDown = (row: number, event: React.KeyboardEvent<any>) => {
    +    if (!this.props.isCommitting) {
    +      return
    +    }
    +
    +    // the commit is already in-flight, but this check prevents the
    +    // user from changing selection and expecting it to work
    +    if (event.key === 'Enter' || event.key === ' ') {
    +      event.preventDefault()
    +    }
    +  }
    +
       public render() {
         const fileList = this.props.workingDirectory.files
         const fileCount = fileList.length
    @@ -401,6 +413,7 @@ export class ChangesList extends React.Component<
               onSelectionChanged={this.props.onFileSelectionChanged}
               invalidationProps={this.props.workingDirectory}
               onRowClick={this.props.onRowClick}
    +          onRowKeyDown={this.onRowKeyDown}
             />
     
             <CommitMessage
    diff --git a/app/src/ui/lib/list/list.tsx b/app/src/ui/lib/list/list.tsx
    index e534ebfd7..c3c07b659 100644
    --- a/app/src/ui/lib/list/list.tsx
    +++ b/app/src/ui/lib/list/list.tsx
    @@ -413,6 +413,11 @@ export class List extends React.Component<IListProps, IListState> {
       }
     
       private onKeyDown = (event: React.KeyboardEvent<any>) => {
    +    // onRowKeyDown previously flagged this event to be prevented
    +    if (event.defaultPrevented) {
    +      return
    +    }
    +
         if (event.key === 'Enter' || event.key === ' ') {
           this.toggleSelection(event)
           event.preventDefault()

    The change required in list.tsx I believe is related to how DOM events propagate, but I haven't researched it deeply and want to ensure it doesn't break other functionality.

    If you want to test a long-running commit without setting a pre-commit hook, here's a test helper I put together that helped me with this spike:

    diff --git a/app/src/lib/git/commit.ts b/app/src/lib/git/commit.ts
    index 826f29ca5..ec719b0e3 100644
    --- a/app/src/lib/git/commit.ts
    +++ b/app/src/lib/git/commit.ts
    @@ -4,11 +4,21 @@ import { Repository } from '../../models/repository'
     import { WorkingDirectoryFileChange } from '../../models/status'
     import { unstageAll } from './reset'
     
    +function delay(ms: number): Promise<void> {
    +  return new Promise<void>((resolve, reject) => {
    +    setTimeout(() => {
    +      resolve()
    +    }, ms)
    +  })
    +}
    +
     export async function createCommit(
       repository: Repository,
       message: string,
       files: ReadonlyArray<WorkingDirectoryFileChange>
     ): Promise<boolean> {
    +  await delay(30000)
    +
       // Clear the staging area, our diffs reflect the difference between the
       // working directory and the last commit (if any) so our commits should
       // do the same thing.
  2. added
    help wanted
    priority-3
    on Oct 18, 2018
  3. added
    bug
    on Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions