Skip to content

Commit 658c467

Browse files
committed
feat: skip matcher when query is empty
1 parent c8f0fe7 commit 658c467

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

builtin/matcher/fzf.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ export function fzf(options: FzfOptions = {}): Matcher {
3535
const forward = options.forward ?? true;
3636

3737
return defineMatcher(async function* (_denops, { items, query }, { signal }) {
38+
if (query.trim() === "") {
39+
yield* items;
40+
return;
41+
}
42+
3843
// Split query into individual terms, ignoring empty strings
39-
const terms = query.split(/\s+/).filter((v) => v.length > 0);
44+
const terms = query.trim().split(/\s+/).filter((v) => v.length > 0);
4045

4146
// deno-lint-ignore no-explicit-any
4247
const filter = async (items: readonly IdItem<any>[], term: string) => {

builtin/matcher/regexp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import { getByteLength } from "../../util/stringutil.ts";
1212
*/
1313
export function regexp(): Matcher {
1414
return defineMatcher(async function* (_denops, { query, items }, { signal }) {
15+
if (query.trim() === "") {
16+
yield* items;
17+
return;
18+
}
19+
1520
// Create a RegExp from the query with global matching enabled
16-
const pattern = new RegExp(query, "g");
21+
const pattern = new RegExp(query.trim(), "g");
1722

1823
// Iterate over each item, applying the regular expression
1924
for await (const item of items) {

builtin/matcher/substring.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ export function substring(options: SubstringOptions = {}): Matcher {
4646

4747
return defineMatcher(
4848
async function* (_denops, { query, items }, { signal }) {
49+
if (query.trim() === "") {
50+
yield* items;
51+
return;
52+
}
53+
4954
const ignoreCase = shouldIgnoreCase(query);
5055
const norm = (v: string): string => (ignoreCase ? v.toLowerCase() : v);
5156
const terms = query
57+
.trim()
5258
.split(/\s+/)
5359
.filter((v) => v.length > 0)
5460
.map(norm);

0 commit comments

Comments
 (0)