Skip to content

Commit 7770fb0

Browse files
committed
fix: continue autocomplete after space
Related to camunda/camunda-modeler#5169
1 parent 0cc33c9 commit 7770fb0

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/autocompletion/variable.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export function variableCompletion({ variables = [], builtins = [] }) {
1919

2020
const options = getVariableSuggestions(variables, builtins);
2121

22+
// Allow spaces for autocomplete suggestions should be the same as feel variable/functions names (eg a-z, A-Z, _, 0-9, <space>)
23+
const validFor = /^[\w ]*$/;
24+
2225
if (!options.length) {
2326
return (context) => null;
2427
}
@@ -36,7 +39,8 @@ export function variableCompletion({ variables = [], builtins = [] }) {
3639
if (isEmpty(nodeBefore, pos)) {
3740
return context.explicit ? {
3841
from: pos,
39-
options
42+
options,
43+
validFor
4044
} : null;
4145
}
4246

@@ -45,9 +49,15 @@ export function variableCompletion({ variables = [], builtins = [] }) {
4549
return null;
4650
}
4751

52+
// find the full typed input, to continue auto-completion after separated names
53+
const typedInput = typeof context.matchBefore === 'function'
54+
? context.matchBefore(/\w[\w ]*$/)
55+
: null;
56+
4857
return {
49-
from: nodeBefore.from,
50-
options
58+
from: typedInput ? typedInput.from : nodeBefore.from,
59+
options,
60+
validFor
5161
};
5262
};
5363
}

test/spec/autocompletion/builtin.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ describe('autocompletion - built-ins', function() {
106106
});
107107

108108

109+
it('should complete multi-word prefix (<get o>)', function() {
110+
111+
const triggerCompletion = setup('get o', [
112+
{
113+
name: 'get or else',
114+
type: 'function',
115+
params: [
116+
{ name: 'value' },
117+
{ name: 'default' }
118+
]
119+
}
120+
]);
121+
122+
// when
123+
const completion = triggerCompletion();
124+
125+
// then
126+
expect(completion).to.exist;
127+
});
128+
129+
109130
it('should not complete for empty context', function() {
110131

111132
// given

test/spec/autocompletion/variable.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ describe('autocompletion - variable', function() {
108108
});
109109

110110

111+
it('should complete variable with underscore and numbers', function() {
112+
113+
// given
114+
const triggerCompletion = setup('test_', [ { name: 'test_123' } ]);
115+
116+
// when
117+
const completion = triggerCompletion();
118+
119+
// then
120+
expect(completion).to.exist;
121+
});
122+
123+
111124
it('should not complete empty expression', function() {
112125

113126
// given

0 commit comments

Comments
 (0)