Commit 4113f7db by David Kaltschmidt

Trigger typeahead on Ctrl-Space

parent 0425b477
...@@ -335,20 +335,30 @@ class QueryField extends React.Component<any, any> { ...@@ -335,20 +335,30 @@ class QueryField extends React.Component<any, any> {
} }
onKeyDown = (event, change) => { onKeyDown = (event, change) => {
if (this.menuEl) {
const { typeaheadIndex, suggestions } = this.state; const { typeaheadIndex, suggestions } = this.state;
switch (event.key) { switch (event.key) {
case 'Escape': { case 'Escape': {
if (this.menuEl) { if (this.menuEl) {
event.preventDefault(); event.preventDefault();
event.stopPropagation();
this.resetTypeahead(); this.resetTypeahead();
return true; return true;
} }
break; break;
} }
case ' ': {
if (event.ctrlKey) {
event.preventDefault();
this.handleTypeahead();
return true;
}
break;
}
case 'Tab': { case 'Tab': {
if (this.menuEl) {
// Dont blur input // Dont blur input
event.preventDefault(); event.preventDefault();
if (!suggestions || suggestions.length === 0) { if (!suggestions || suggestions.length === 0) {
...@@ -364,18 +374,24 @@ class QueryField extends React.Component<any, any> { ...@@ -364,18 +374,24 @@ class QueryField extends React.Component<any, any> {
this.applyTypeahead(change, suggestion); this.applyTypeahead(change, suggestion);
return true; return true;
} }
break;
}
case 'ArrowDown': { case 'ArrowDown': {
if (this.menuEl) {
// Select next suggestion // Select next suggestion
event.preventDefault(); event.preventDefault();
this.setState({ typeaheadIndex: typeaheadIndex + 1 }); this.setState({ typeaheadIndex: typeaheadIndex + 1 });
}
break; break;
} }
case 'ArrowUp': { case 'ArrowUp': {
if (this.menuEl) {
// Select previous suggestion // Select previous suggestion
event.preventDefault(); event.preventDefault();
this.setState({ typeaheadIndex: Math.max(0, typeaheadIndex - 1) }); this.setState({ typeaheadIndex: Math.max(0, typeaheadIndex - 1) });
}
break; break;
} }
...@@ -384,7 +400,6 @@ class QueryField extends React.Component<any, any> { ...@@ -384,7 +400,6 @@ class QueryField extends React.Component<any, any> {
break; break;
} }
} }
}
return undefined; return undefined;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment