mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Console] Fix autocomplete on typing in every letter (#171952)
Closes #171951
## Summary
This PR fixes autocomplete to show suggestions even if user types in
every letter.

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
### For maintainers
- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
## Release note
Fixes autocomplete to show suggestions even if user types in every
letter
This commit is contained in:
parent
774385156c
commit
1f5a3a08a5
2 changed files with 18 additions and 7 deletions
|
@ -103,6 +103,10 @@ describe('looksLikeTypingIn', () => {
|
|||
{ preamble: 'GET _cat/indices?s=index&exp', autocomplete: 'and_wildcards', input: '=' },
|
||||
{ preamble: 'GET _cat/indices?v&', autocomplete: 'expand_wildcards', input: '=' },
|
||||
{ preamble: 'GET _cat/indices?v&exp', autocomplete: 'and_wildcards', input: '=' },
|
||||
// autocomplete skips one iteration of token evaluation if user types in every letter
|
||||
{ preamble: 'GET .kibana', autocomplete: '/', input: '_' }, // token '/' may not be evaluated
|
||||
{ preamble: 'GET .kibana', autocomplete: ',', input: '.' }, // token ',' may not be evaluated
|
||||
{ preamble: 'GET .kibana', autocomplete: '?', input: 'k' }, // token '?' may not be evaluated
|
||||
];
|
||||
for (const c of cases) {
|
||||
const name =
|
||||
|
|
|
@ -11,6 +11,7 @@ import type { CoreEditor, Position, Token } from '../../types';
|
|||
enum Move {
|
||||
ForwardOneCharacter = 1,
|
||||
ForwardOneToken, // the column position may jump to the next token by autocomplete
|
||||
ForwardTwoTokens, // the column position could jump two tokens due to autocomplete
|
||||
}
|
||||
|
||||
const knownTypingInTokenTypes = new Map<Move, Map<string, Set<string>>>([
|
||||
|
@ -43,6 +44,10 @@ const knownTypingInTokenTypes = new Map<Move, Map<string, Set<string>>>([
|
|||
['whitespace', new Set(['url.comma', 'url.questionmark', 'url.slash'])],
|
||||
]),
|
||||
],
|
||||
[
|
||||
Move.ForwardTwoTokens,
|
||||
new Map<string, Set<string>>([['url.part', new Set(['url.param', 'url.part'])]]),
|
||||
],
|
||||
]);
|
||||
|
||||
const getOneCharacterNextOnTheRight = (pos: Position, coreEditor: CoreEditor): string => {
|
||||
|
@ -75,14 +80,16 @@ export const looksLikeTypingIn = (
|
|||
currentToken.value.length === 1 &&
|
||||
getOneCharacterNextOnTheRight(currentToken.position, coreEditor) === ''
|
||||
) {
|
||||
const move =
|
||||
const moves =
|
||||
lastEvaluatedToken.position.column + 1 === currentToken.position.column
|
||||
? Move.ForwardOneCharacter
|
||||
: Move.ForwardOneToken;
|
||||
const tokenTypesPairs = knownTypingInTokenTypes.get(move) ?? new Map<string, Set<string>>();
|
||||
const currentTokenTypes = tokenTypesPairs.get(lastEvaluatedToken.type) ?? new Set<string>();
|
||||
if (currentTokenTypes.has(currentToken.type)) {
|
||||
return true;
|
||||
? [Move.ForwardOneCharacter]
|
||||
: [Move.ForwardOneToken, Move.ForwardTwoTokens];
|
||||
for (const move of moves) {
|
||||
const tokenTypesPairs = knownTypingInTokenTypes.get(move) ?? new Map<string, Set<string>>();
|
||||
const currentTokenTypes = tokenTypesPairs.get(lastEvaluatedToken.type) ?? new Set<string>();
|
||||
if (currentTokenTypes.has(currentToken.type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue