Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
correct multiple match marking on select2
Browse files Browse the repository at this point in the history
  • Loading branch information
glasnt committed Sep 5, 2014
1 parent db8583d commit f8b7efd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions vendor/assets/javascripts/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ the specific language governing permissions and limitations under the Apache Lic
dest.attr("class", replacements.join(" "));
}

// Extended to match multiple terms, delimited by space
// Extended to match multiple terms, delimited by space
function markMatch(text, term, markup, escapeMarkup) {
var text_ = stripDiacritics(text.toUpperCase())
var term_ = stripDiacritics(term.toUpperCase())
Expand All @@ -376,19 +376,19 @@ the specific language governing permissions and limitations under the Apache Lic

var start = 0
$.each(terms, function(i, t) {
var x = text_.substring(start, text_.length).indexOf(t) + start
index.push([x, t.length]);
start = x+t.length

var hits = indiciesOf(text_,t);
$.each(hits, function(i, x) { index.push([x, t.length]) })
})

if (index.length === 0) {
markup.push(escapeMarkup(text));
return;
}

index = index.sort();

var point = 0
$.each(index, function(i, pair) {
$.each(index, function(y, pair) {
var i = pair[0];
var len = pair[1];
markup.push(escapeMarkup(text.substring(point, i)));
Expand All @@ -401,6 +401,17 @@ the specific language governing permissions and limitations under the Apache Lic
markup.push(escapeMarkup(text.substring(point, text_.length)));
}

function indiciesOf(text, search) {
var start = 0;
var index, indices = []
while ((index = text.indexOf(search, start)) > -1) {
indices.push(index);
start = index + search.length;
}
return indices;
}


function defaultEscapeMarkup(markup) {
var replace_map = {
'\\': '\',
Expand Down

0 comments on commit f8b7efd

Please sign in to comment.