Skip to content

Commit 5618046

Browse files
authoredOct 2, 2023
feat: allow setting completion.ignoreCaption
By default, we use the caption value of a completion result to filter results. This might cause issues for users who want to have a caption say something else than what's going to be inserted (e.g. when they are using inline preview). This allows setting ignoreCaption to true after which filtering will be done following the value or snippet parameters.
2 parents 678364b + 96aca84 commit 5618046

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed
 

‎ace.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ export namespace Ace {
10671067
parentNode?: HTMLElement;
10681068
setSelectOnHover?: Boolean;
10691069
stickySelectionDelay?: Number;
1070+
ignoreCaption?: Boolean;
10701071
emptyMessage?(prefix: String): String;
10711072
getPopup(): AcePopup;
10721073
showPopup(editor: Editor, options: CompletionOptions): void;

‎src/autocomplete.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,10 @@ class Autocomplete {
399399
var prefix = util.getCompletionPrefix(this.editor);
400400
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
401401
this.base.$insertRight = true;
402-
var completionOptions = { exactMatch: this.exactMatch };
402+
var completionOptions = {
403+
exactMatch: this.exactMatch,
404+
ignoreCaption: this.ignoreCaption
405+
};
403406
this.getCompletionProvider({
404407
prefix,
405408
pos

‎src/autocomplete_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,58 @@ module.exports = {
726726

727727
done();
728728
}, 500);
729+
},
730+
"test: should filter using caption if ignoreCaption false": function() {
731+
var editor = initEditor("hello world\n");
732+
733+
var completer = {
734+
getCompletions: function (editor, session, pos, prefix, callback) {
735+
var completions = [
736+
{
737+
caption: "caption",
738+
value: "value"
739+
}
740+
];
741+
callback(null, completions);
742+
}
743+
};
744+
745+
editor.completers = [completer];
746+
747+
var completer = Autocomplete.for(editor);
748+
749+
// Should filter using the caption if set to false.
750+
completer.ignoreCaption = false;
751+
user.type("cap");
752+
assert.equal(completer.popup.isOpen, true);
753+
},
754+
"test: should filter using value if ignoreCaption true": function() {
755+
var editor = initEditor("hello world\n");
756+
757+
var completer = {
758+
getCompletions: function (editor, session, pos, prefix, callback) {
759+
var completions = [
760+
{
761+
caption: "caption",
762+
value: "value"
763+
}
764+
];
765+
callback(null, completions);
766+
}
767+
};
768+
769+
editor.completers = [completer];
770+
771+
var completer = Autocomplete.for(editor);
772+
773+
// Should not filter using the caption if set to true.
774+
completer.ignoreCaption = true;
775+
user.type("cap");
776+
assert.equal(completer.popup, undefined);
777+
778+
// Should filter using the value instead.
779+
user.type(" value");
780+
assert.equal(completer.popup.isOpen, true);
729781
}
730782
};
731783

0 commit comments

Comments
 (0)
Please sign in to comment.