App-Mxpress-PDF
view release on metacpan or search on metacpan
public/javascripts/ace/ext-prompt.js view on Meta::CPAN
if (this.popup) {
this.popup.destroy();
var el = this.popup.container;
if (el && el.parentNode)
el.parentNode.removeChild(el);
}
if (this.editor && this.editor.completer == this)
this.editor.completer == null;
this.popup = null;
};
}).call(Autocomplete.prototype);
Autocomplete.for = function(editor) {
if (editor.completer) {
return editor.completer;
}
if (config.get("sharedPopups")) {
if (!Autocomplete.$shared)
Autocomplete.$sharedInstance = new Autocomplete();
editor.completer = Autocomplete.$sharedInstance;
} else {
editor.completer = new Autocomplete();
editor.once("destroy", function(e, editor) {
editor.completer.destroy();
});
}
return editor.completer;
};
Autocomplete.startCommand = {
name: "startAutocomplete",
exec: function(editor, options) {
var completer = Autocomplete.for(editor);
completer.autoInsert = false;
completer.autoSelect = true;
completer.showPopup(editor, options);
completer.cancelContextMenu();
},
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
};
var FilteredList = function(array, filterText) {
this.all = array;
this.filtered = array;
this.filterText = filterText || "";
this.exactMatch = false;
};
(function(){
this.setFilter = function(str) {
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
var matches = this.filtered;
else
var matches = this.all;
this.filterText = str;
matches = this.filterCompletions(matches, this.filterText);
matches = matches.sort(function(a, b) {
return b.exactMatch - a.exactMatch || b.$score - a.$score
|| (a.caption || a.value).localeCompare(b.caption || b.value);
});
var prev = null;
matches = matches.filter(function(item){
var caption = item.snippet || item.caption || item.value;
if (caption === prev) return false;
prev = caption;
return true;
});
this.filtered = matches;
};
this.filterCompletions = function(items, needle) {
var results = [];
var upper = needle.toUpperCase();
var lower = needle.toLowerCase();
loop: for (var i = 0, item; item = items[i]; i++) {
var caption = item.caption || item.value || item.snippet;
if (!caption) continue;
var lastIndex = -1;
var matchMask = 0;
var penalty = 0;
var index, distance;
if (this.exactMatch) {
if (needle !== caption.substr(0, needle.length))
continue loop;
} else {
var fullMatchIndex = caption.toLowerCase().indexOf(lower);
if (fullMatchIndex > -1) {
penalty = fullMatchIndex;
} else {
for (var j = 0; j < needle.length; j++) {
var i1 = caption.indexOf(lower[j], lastIndex + 1);
var i2 = caption.indexOf(upper[j], lastIndex + 1);
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
if (index < 0)
continue loop;
distance = index - lastIndex - 1;
if (distance > 0) {
if (lastIndex === -1)
penalty += 10;
penalty += distance;
matchMask = matchMask | (1 << j);
}
lastIndex = index;
}
}
}
item.matchMask = matchMask;
item.exactMatch = penalty ? 0 : 1;
item.$score = (item.score || 0) - penalty;
results.push(item);
}
return results;
};
}).call(FilteredList.prototype);
exports.Autocomplete = Autocomplete;
exports.FilteredList = FilteredList;
( run in 1.040 second using v1.01-cache-2.11-cpan-ceb78f64989 )