Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates in response to code review
  • Loading branch information
brandonpayton committed Jun 29, 2018
commit 80e223465764d293aefade273a3acfad8b759103
2 changes: 1 addition & 1 deletion components/autocomplete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Whether to apply debouncing for the autocompleter. Set to true to enable debounc
Here is a contrived completer for feelings. It yields editable tokens like "!resolute".

```jsx
const fruitCompleter = {
const feelingCompleter = {
name: 'feeling',
// The prefix that triggers this completer
triggerPrefix: '!',
Expand Down
22 changes: 12 additions & 10 deletions components/autocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,19 +658,21 @@ export class Autocomplete extends Component {
}

handleKeyDown( event ) {
const { ctrlKey, shiftKey, altKey, metaKey } = event;
const { keyCode, ctrlKey, shiftKey, altKey, metaKey } = event;
const { open, suppress, query } = this.state;
if (
event.keyCode === SPACE &&
! ( ctrlKey || shiftKey || altKey || metaKey ) &&
open && suppress !== open.idx
) {
const completerIsOpenAndUnsuppressed = open && suppress !== open.idx;

if ( ! completerIsOpenAndUnsuppressed ) {
return;
}

if ( keyCode === SPACE && ! ( ctrlKey || shiftKey || altKey || metaKey ) ) {
// Insert a completion when the user spaces after typing an exact option match.
const exactMatchSearch = new RegExp( '^' + escapeRegExp( query ) + '$', 'i' );
const wasOptions = this.state[ 'options_' + open.idx ];
const [ firstMatchingOption ] = filterOptions( exactMatchSearch, wasOptions );
if ( firstMatchingOption ) {
this.select( firstMatchingOption );
const currentCompleterOptions = this.state[ 'options_' + open.idx ];
const [ exactMatch ] = filterOptions( exactMatchSearch, currentCompleterOptions );
if ( exactMatch ) {
this.select( exactMatch );
}
}
}
Expand Down