瀏覽代碼

fix: Code clean up

version-14
ChillarAnand 3 年之前
父節點
當前提交
c94edc21f4
共有 2 個文件被更改,包括 30 次插入35 次删除
  1. +6
    -11
      frappe/public/js/frappe/ui/toolbar/fuzzy_match.js
  2. +24
    -24
      frappe/public/js/frappe/ui/toolbar/search_utils.js

+ 6
- 11
frappe/public/js/frappe/ui/toolbar/fuzzy_match.js 查看文件

@@ -31,7 +31,7 @@ const UNMATCHED_LETTER_PENALTY = -1;
* @returns [boolean, number] a boolean which tells if pattern was
* found or not and a search score
*/
function fuzzy_match(pattern, str) {
export function fuzzy_match(pattern, str) {
const recursion_count = 0;
const recursion_limit = 10;
const matches = [];
@@ -42,7 +42,7 @@ function fuzzy_match(pattern, str) {
str,
0 /* pattern_cur_index */,
0 /* str_curr_index */,
null /* src_matces */,
null /* src_matches */,
matches,
max_matches,
0 /* next_match */,
@@ -56,7 +56,7 @@ function fuzzy_match_recursive(
str,
pattern_cur_index,
str_curr_index,
src_matces,
src_matches,
matches,
max_matches,
next_match,
@@ -91,8 +91,8 @@ function fuzzy_match_recursive(
return [false, out_score];
}

if (first_match && src_matces) {
matches = [...src_matces];
if (first_match && src_matches) {
matches = [...src_matches];
first_match = false;
}

@@ -116,7 +116,7 @@ function fuzzy_match_recursive(
best_recursive_matches = [...recursive_matches];
best_recursive_score = recursive_score;
}
recursiveMatch = true;
recursive_match = true;
}

matches[next_match++] = str_curr_index;
@@ -189,8 +189,3 @@ function fuzzy_match_recursive(
}
return [false, out_score];
}


module.exports = {
fuzzy_match
};

+ 24
- 24
frappe/public/js/frappe/ui/toolbar/search_utils.js 查看文件

@@ -540,36 +540,36 @@ frappe.search.utils = {
},

bolden_match_part: function(str, subseq) {
if(fuzzy_match(subseq, str)[0] === false) {
if (fuzzy_match(subseq, str)[0] === false) {
return str;
}
if(str.indexOf(subseq) == 0) {
var tail = str.split(subseq)[1];
return '<mark>' + subseq + '</mark>' + tail;
if (str.indexOf(subseq) == 0) {
var tail = str.split(subseq)[1];
return '<mark>' + subseq + '</mark>' + tail;
}
var rendered = "";
var str_orig = str;
var str = str.toLowerCase();
var str_len = str.length;
var subseq = subseq.toLowerCase();

outer: for(var i = 0, j = 0; i < subseq.length; i++) {
var sub_ch = subseq.charCodeAt(i);
while(j < str_len) {
if(str.charCodeAt(j) === sub_ch) {
var str_char = str_orig.charAt(j);
if(str_char === str_char.toLowerCase()) {
rendered += '<mark>' + subseq.charAt(i) + '</mark>';
} else {
rendered += '<mark>' + subseq.charAt(i).toUpperCase() + '</mark>';
}
j++;
continue outer;
}
rendered += str_orig.charAt(j);
j++;
}
return str_orig;
str = str.toLowerCase();
subseq = subseq.toLowerCase();

outer: for (var i = 0, j = 0; i < subseq.length; i++) {
var sub_ch = subseq.charCodeAt(i);
while (j < str_len) {
if (str.charCodeAt(j) === sub_ch) {
var str_char = str_orig.charAt(j);
if (str_char === str_char.toLowerCase()) {
rendered += '<mark>' + subseq.charAt(i) + '</mark>';
} else {
rendered += '<mark>' + subseq.charAt(i).toUpperCase() + '</mark>';
}
j++;
continue outer;
}
rendered += str_orig.charAt(j);
j++;
}
return str_orig;
}
rendered += str_orig.slice(j);
return rendered;


Loading…
取消
儲存