Skip to content

Commit 0db7585

Browse files
authored
feat(popup): add supporting skipFilter flag for popup item (#5740)
1 parent 09fba2e commit 0db7585

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/autocomplete.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var preventParentScroll = require("./lib/scroll").preventParentScroll;
2828
* @property {string} [docText] - a plain text that would be displayed as an additional popup. If `docHTML` exists,
2929
* it would be used instead of `docText`.
3030
* @property {string} [completerId] - the identifier of the completer
31+
* @property {boolean} [skipFilter] - a boolean value to decide if the popup item is going to skip the filtering process done using prefix text.
3132
* @property {import("../ace-internal").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental)
3233
* @property {any} [command] - A command to be executed after the completion is inserted (experimental)
3334
* @property {string} [snippet] - a text snippet that would be inserted when the completion is selected
@@ -1055,6 +1056,10 @@ class FilteredList {
10551056
var upper = needle.toUpperCase();
10561057
var lower = needle.toLowerCase();
10571058
loop: for (var i = 0, item; item = items[i]; i++) {
1059+
if (item.skipFilter) {
1060+
results.push(item);
1061+
continue;
1062+
}
10581063
var caption = (!this.ignoreCaption && item.caption) || item.value || item.snippet;
10591064
if (!caption) continue;
10601065
var lastIndex = -1;

src/autocomplete_test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,58 @@ module.exports = {
944944
user.type(" value");
945945
assert.equal(completer.popup.isOpen, true);
946946
},
947+
"test: should skip filter if skipFilter flag is set to true in completion": function() {
948+
var editor = initEditor("hello world\n");
949+
950+
var completer = {
951+
getCompletions: function (editor, session, pos, prefix, callback) {
952+
var completions = [
953+
{
954+
value: "example value",
955+
skipFilter: true
956+
}
957+
];
958+
callback(null, completions);
959+
}
960+
};
961+
962+
editor.completers = [completer];
963+
964+
var completer = Autocomplete.for(editor);
965+
// should not do filter out the completion item where skipFilter is true
966+
user.type("notMatchingText");
967+
assert.equal(completer.popup.data.length, 1);
968+
assert.equal(completer.popup.isOpen, true);
969+
},
970+
"test: should use filter if skipFilter flag is set to false in completion": function() {
971+
var editor = initEditor("hello world\n");
972+
973+
var completer = {
974+
getCompletions: function (editor, session, pos, prefix, callback) {
975+
var completions = [
976+
{
977+
value: "example value",
978+
skipFilter: false
979+
}
980+
];
981+
callback(null, completions);
982+
}
983+
};
984+
985+
editor.completers = [completer];
986+
987+
var completer = Autocomplete.for(editor);
988+
989+
// should do filter out the completion item where skipFilter is false
990+
user.type("notMatchingText");
991+
assert.equal(completer.popup, undefined);
992+
993+
// normal filtering mechanism should work fine
994+
user.type(" ex");
995+
assert.equal(completer.popup.isOpen, true);
996+
assert.equal(completer.popup.data.length, 1);
997+
},
998+
947999
"test: should add inline preview content to aria-describedby": function(done) {
9481000
var editor = initEditor("fun");
9491001

types/ace-modules.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,6 +3224,10 @@ declare module "ace-code/src/autocomplete" {
32243224
* - the identifier of the completer
32253225
*/
32263226
completerId?: string;
3227+
/**
3228+
* - a boolean value to decide if the popup item is going to skip the filtering process done using prefix text.
3229+
*/
3230+
skipFilter?: boolean;
32273231
/**
32283232
* - An object specifying the range of text to be replaced with the new completion value (experimental)
32293233
*/

0 commit comments

Comments
 (0)