Skip to content
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
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 @@ -5,7 +5,7 @@
"use strict";

var sendKey = require("./test/user").type;
var {buildDom} = require("./lib/dom");

Check warning on line 8 in src/autocomplete_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'buildDom' is assigned a value but never used
var ace = require("./ace");
var assert = require("./test/assertions");
var user = require("./test/user");
Expand Down Expand Up @@ -944,6 +944,58 @@
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 Expand Up @@ -1599,7 +1651,7 @@
assert.equal(Autocomplete.$sharedInstance == undefined, true);
config.set("sharedPopups", true);
var editor = initEditor("");
var completer = Autocomplete.for(editor);

Check warning on line 1654 in src/autocomplete_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'completer' is assigned a value but never used
assert.equal(Autocomplete.$sharedInstance == undefined, false);
},
"test: changing completion should render scrollbars correctly": function (done) {
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