Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Fix autocomplete on typing in every letter #171952

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>>>([
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
Loading