Skip to content

Commit 8ffe67e

Browse files
committed
Focus changes files when navigating to Changes tab
Fixes #103
1 parent fcb24a3 commit 8ffe67e

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

app/src/ui/changes/filter-changes-list.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ export class FilterChangesList extends React.Component<
318318
> {
319319
private filterTextBox: TextBox | undefined = undefined
320320
private headerRef = createObservableRef<HTMLDivElement>()
321-
private filterOptionsButtonRef: HTMLButtonElement | null = null
322321
private includeAllCheckBoxRef = React.createRef<Checkbox>()
323322
private filterListRef =
324323
React.createRef<AugmentedSectionFilterList<IChangesListItem>>()
@@ -1290,12 +1289,7 @@ export class FilterChangesList extends React.Component<
12901289
}
12911290

12921291
public focus() {
1293-
if (this.props.showChangesFilter) {
1294-
this.filterOptionsButtonRef?.focus()
1295-
return
1296-
}
1297-
1298-
this.includeAllCheckBoxRef.current?.focus()
1292+
this.filterListRef.current?.focus()
12991293
}
13001294

13011295
private onChangedFileClick = (

app/src/ui/lib/augmented-filter-list.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ export class AugmentedSectionFilterList<
402402
)
403403
}
404404

405+
public focus() {
406+
this.list?.focus()
407+
}
408+
405409
public selectNextItem(
406410
focus: boolean = false,
407411
inDirection: SelectionDirection = 'down'

app/src/ui/lib/list/section-list.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,18 @@ export class SectionList extends React.Component<
17681768
lastSelectedRow !== undefined &&
17691769
isValidRow(lastSelectedRow, rowCount)
17701770
) {
1771-
this.scrollRowToVisible(lastSelectedRow)
1771+
const rowElement = this.rowRefs.get(lastSelectedRow)
1772+
if (rowElement !== undefined) {
1773+
this.focusRow = lastSelectedRow
1774+
rowElement.focus({ preventScroll: true })
1775+
} else {
1776+
// Selected row is not yet materialized in the DOM (virtualized away).
1777+
// Fall back to the first row to avoid a no-focus state.
1778+
const firstRow: RowIndexPath = { section: 0, row: 0 }
1779+
if (isValidRow(firstRow, rowCount)) {
1780+
this.scrollRowToVisible(firstRow)
1781+
}
1782+
}
17721783
} else {
17731784
// TODO: decide which grid to focus
17741785
// if (this.grid) {

app/src/ui/repository.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,10 @@ export class RepositoryView extends React.Component<
852852
this.props.repository,
853853
section
854854
)
855+
856+
if (section === RepositorySectionTab.Changes) {
857+
this.focusChangesNeeded = true
858+
}
855859
}
856860

857861
private onTabClicked = (tab: Tab) => {
@@ -861,6 +865,9 @@ export class RepositoryView extends React.Component<
861865
this.props.repository,
862866
section
863867
)
868+
if (section === RepositorySectionTab.Changes) {
869+
this.focusChangesNeeded = true
870+
}
864871
if (!!section) {
865872
this.props.dispatcher.updateCompareForm(this.props.repository, {
866873
filterText: '',

0 commit comments

Comments
 (0)