Skip to content

Commit dabc06d

Browse files
authored
Feature: Case-insensitive "find files in repo" (#21269)
This (short) PR builds upon #15028 and makes the file search case-insensitive. Previously, having a file named `TestFile.cs` would not be shown if `test` was typed in the search box. This now changes the matching function to be case-insensitive (without affecting the UI). The matching function, `strSubMatch`, is only used for this feature (it has been introduced by #15028), meaning that this PR does not affect the behaviour of any unrelated functionality of Gitea.
1 parent 8cd3237 commit dabc06d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

web_src/js/utils.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,17 @@ export function parseIssueHref(href) {
6464
export function strSubMatch(full, sub) {
6565
const res = [''];
6666
let i = 0, j = 0;
67-
while (i < sub.length && j < full.length) {
68-
while (j < full.length) {
69-
if (sub[i] === full[j]) {
70-
if (res.length % 2 !== 0) res.push('');
71-
res[res.length - 1] += full[j];
72-
j++;
73-
i++;
74-
} else {
75-
if (res.length % 2 === 0) res.push('');
76-
res[res.length - 1] += full[j];
77-
j++;
78-
break;
79-
}
67+
const subLower = sub.toLowerCase(), fullLower = full.toLowerCase();
68+
while (i < subLower.length && j < fullLower.length) {
69+
if (subLower[i] === fullLower[j]) {
70+
if (res.length % 2 !== 0) res.push('');
71+
res[res.length - 1] += full[j];
72+
j++;
73+
i++;
74+
} else {
75+
if (res.length % 2 === 0) res.push('');
76+
res[res.length - 1] += full[j];
77+
j++;
8078
}
8179
}
8280
if (i !== sub.length) {

web_src/js/utils.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ test('strSubMatch', () => {
9595
expect(strSubMatch('abc', 'z')).toEqual(['abc']);
9696
expect(strSubMatch('abc', 'az')).toEqual(['abc']);
9797

98+
expect(strSubMatch('abc', 'aC')).toEqual(['', 'a', 'b', 'c']);
99+
expect(strSubMatch('abC', 'ac')).toEqual(['', 'a', 'b', 'C']);
100+
98101
expect(strSubMatch('aabbcc', 'abc')).toEqual(['', 'a', 'a', 'b', 'b', 'c', 'c']);
99102
expect(strSubMatch('the/directory', 'hedir')).toEqual(['t', 'he', '/', 'dir', 'ectory']);
100103
});

0 commit comments

Comments
 (0)