TERMINAL: Fix autocomplete for mixed case strings (#1323)

This commit is contained in:
Yichi Zhang 2024-05-29 11:34:46 -07:00 committed by GitHub
parent bd6585617c
commit 54d099e552
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -59,17 +59,16 @@ function longestCommonStart(strings: string[]): string {
return ""; return "";
} }
const A: string[] = strings.concat().sort(); const a1: string = strings[0];
const a1: string = A[0]; for (let i = 0; i < a1.length; ++i) {
const a2: string = A[A.length - 1]; const chr = a1.charAt(i).toUpperCase();
const L: number = a1.length; for (let s = 1; s < strings.length; ++s) {
let i = 0; if (chr !== strings[s].charAt(i).toUpperCase()) {
const areEqualCaseInsensitive = (a: string, b: string) => a.toUpperCase() === b.toUpperCase();
while (i < L && areEqualCaseInsensitive(a1.charAt(i), a2.charAt(i))) {
i++;
}
return a1.substring(0, i); return a1.substring(0, i);
}
}
}
return a1;
} }
// Returns whether an array contains entirely of string objects // Returns whether an array contains entirely of string objects