Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
fix wrapping around first/last item in autocomplete (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
keforbes authored and extr0py committed Mar 10, 2017
1 parent 4a52a21 commit 1f3e65e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions browser/src/UI/Reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ export const autoCompletionReducer = (s: State.IAutoCompletionInfo | null, a: Ac
return s
}

const currentEntryCount = s.entries.length
// TODO: sync max display items (10) with value in AutoCompletion.render() (AutoCompletion.tsx)
const currentEntryCount = Math.min(10, s.entries.length)

switch (a.type) {
case "NEXT_AUTO_COMPLETION":
Expand All @@ -256,7 +257,7 @@ export const autoCompletionReducer = (s: State.IAutoCompletionInfo | null, a: Ac
})
case "PREVIOUS_AUTO_COMPLETION":
return Object.assign({}, s, {
selectedIndex: (s.selectedIndex - 1) % currentEntryCount,
selectedIndex: s.selectedIndex > 0 ? s.selectedIndex - 1 : currentEntryCount - 1,
})
default:
return Object.assign({}, s, {
Expand Down
1 change: 1 addition & 0 deletions browser/src/UI/components/AutoCompletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class AutoCompletion extends React.Component<IAutoCompletionProps, void>
return null
}

// TODO: sync max display items (10) with value in Reducer.autoCompletionReducer() (Reducer.ts)
const firstTenEntries = _.take(this.props.entries, 10)

const entries = firstTenEntries.map((s, i) => {
Expand Down

0 comments on commit 1f3e65e

Please sign in to comment.