Skip to content

Commit

Permalink
feat(popup): add supporting skipFilter flag for popup item
Browse files Browse the repository at this point in the history
  • Loading branch information
nlujjawal committed Feb 7, 2025
1 parent 09fba2e commit 1aef671
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var preventParentScroll = require("./lib/scroll").preventParentScroll;
* @property {string} [docText] - a plain text that would be displayed as an additional popup. If `docHTML` exists,
* it would be used instead of `docText`.
* @property {string} [completerId] - the identifier of the completer
* @property {boolean} [skipFilter] - a boolean value to decide if the popup item is going to skip the filtering process done using prefix text.
* @property {import("../ace-internal").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental)
* @property {any} [command] - A command to be executed after the completion is inserted (experimental)
* @property {string} [snippet] - a text snippet that would be inserted when the completion is selected
Expand Down Expand Up @@ -1055,6 +1056,10 @@ class FilteredList {
var upper = needle.toUpperCase();
var lower = needle.toLowerCase();
loop: for (var i = 0, item; item = items[i]; i++) {
if (item.skipFilter) {
results.push(item);
continue;
}
var caption = (!this.ignoreCaption && item.caption) || item.value || item.snippet;
if (!caption) continue;
var lastIndex = -1;
Expand Down
52 changes: 52 additions & 0 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,58 @@ module.exports = {
user.type(" value");
assert.equal(completer.popup.isOpen, true);
},
"test: should skip filter if skipFilter flag is set to true in completion": function() {
var editor = initEditor("hello world\n");

var completer = {
getCompletions: function (editor, session, pos, prefix, callback) {
var completions = [
{
value: "example value",
skipFilter: true
}
];
callback(null, completions);
}
};

editor.completers = [completer];

var completer = Autocomplete.for(editor);
// should not do filter out the completion item where skipFilter is true
user.type("notMatchingText");
assert.equal(completer.popup.data.length, 1);
assert.equal(completer.popup.isOpen, true);
},
"test: should use filter if skipFilter flag is set to false in completion": function() {
var editor = initEditor("hello world\n");

var completer = {
getCompletions: function (editor, session, pos, prefix, callback) {
var completions = [
{
value: "example value",
skipFilter: false
}
];
callback(null, completions);
}
};

editor.completers = [completer];

var completer = Autocomplete.for(editor);

// should do filter out the completion item where skipFilter is false
user.type("notMatchingText");
assert.equal(completer.popup, undefined);

// normal filtering mechanism should work fine
user.type(" ex");
assert.equal(completer.popup.isOpen, true);
assert.equal(completer.popup.data.length, 1);
},

"test: should add inline preview content to aria-describedby": function(done) {
var editor = initEditor("fun");

Expand Down
4 changes: 4 additions & 0 deletions types/ace-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,10 @@ declare module "ace-code/src/autocomplete" {
* - the identifier of the completer
*/
completerId?: string;
/**
* - a boolean value to decide if the popup item is going to skip the filtering process done using prefix text.
*/
skipFilter?: boolean;
/**
* - An object specifying the range of text to be replaced with the new completion value (experimental)
*/
Expand Down

0 comments on commit 1aef671

Please sign in to comment.