Skip to content

Commit 3ce8387

Browse files
committed
fix: ignore Enter key when no tasks match the search query
Previously, pressing Enter with zero filtered results would exit the interactive task selector without selecting anything. Now it does nothing, keeping the selector open so the user can refine their search.
1 parent 0cc4755 commit 3ce8387

4 files changed

Lines changed: 86 additions & 3 deletions

File tree

crates/vite_select/src/interactive.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,10 @@ pub fn run(
297297
std::process::exit(130);
298298
}
299299
KeyCode::Enter => {
300-
if let Some(idx) = state.selected_original_index() {
301-
*selected_index = idx;
302-
}
300+
let Some(idx) = state.selected_original_index() else {
301+
continue;
302+
};
303+
*selected_index = idx;
303304
cleanup(&mut out, &state)?;
304305
return Ok(());
305306
}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ steps = [
117117
{ command = "vp run", interactions = [{ "expect-milestone" = "task-select::0" }, { "write" = "t" }, { "expect-milestone" = "task-select:t:0" }, { "write-key" = "enter" }] },
118118
]
119119

120+
# Interactive: Enter with no matching results does nothing
121+
[[e2e]]
122+
name = "interactive enter with no results does nothing"
123+
cwd = "packages/app"
124+
steps = [
125+
{ command = "vp run", interactions = [{ "expect-milestone" = "task-select::0" }, { "write" = "zzzzz" }, { "expect-milestone" = "task-select:zzzzz:0" }, { "write-key" = "enter" }, { "write-key" = "escape" }, { "expect-milestone" = "task-select::0" }, { "write-key" = "enter" }] },
126+
]
127+
120128
# Typo inside a task script should fail with an error, NOT show a list
121129
[[e2e]]
122130
name = "typo in task script fails without list"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vp run
6+
@ expect-milestone: task-select::0
7+
Search task (↑/to move, enter to select):
8+
> build: echo build app
9+
lint: echo lint app
10+
test: echo test app
11+
lib#build: echo build lib
12+
lib#lint: echo lint lib
13+
lib#test: echo test lib
14+
lib#typecheck: echo typecheck lib
15+
task-select-test#check: echo check root
16+
task-select-test#clean: echo clean root
17+
task-select-test#deploy: echo deploy root
18+
task-select-test#docs: echo docs root
19+
task-select-test#format: echo format root
20+
(…3 more)
21+
@ write: zzzzz
22+
@ expect-milestone: task-select:zzzzz:0
23+
Search task (↑/to move, enter to select): zzzzz
24+
No matching tasks.
25+
@ write-key: enter
26+
@ write-key: escape
27+
@ expect-milestone: task-select::0
28+
Search task (↑/to move, enter to select):
29+
> build: echo build app
30+
lint: echo lint app
31+
test: echo test app
32+
lib#build: echo build lib
33+
lib#lint: echo lint lib
34+
lib#test: echo test lib
35+
lib#typecheck: echo typecheck lib
36+
task-select-test#check: echo check root
37+
task-select-test#clean: echo clean root
38+
task-select-test#deploy: echo deploy root
39+
task-select-test#docs: echo docs root
40+
task-select-test#format: echo format root
41+
(…3 more)
42+
@ write-key: enter
43+
~/packages/app$ echo build appcache disabled: built-in command
44+
build app
45+
46+
47+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
48+
Vite+ Task RunnerExecution Summary
49+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
50+
51+
Statistics: 1 tasks0 cache hits0 cache misses1 cache disabled
52+
Performance: 0% cache hit rate
53+
54+
Task Details:
55+
────────────────────────────────────────────────
56+
[1] app#build: ~/packages/app$ echo build app
57+
Cache disabled for built-in command
58+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

packages/tools/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
"json-edit": "./src/json-edit.ts",
1010
"replace-file-content": "./src/replace-file-content.ts"
1111
},
12+
"scripts": {
13+
"build": "tsc -p tsconfig.build.json tsc -p tsconfig.build.jsontsc -p tsconfig.build.jsontsc -p tsconfig.build.jsontsc -p tsconfig.build.jsontsc -p tsconfig.build.json -p tsconfig.build.json -p tsconfig.build.json -p tsconfig.build.json -p tsconfig.build.json",
14+
"lint": "oxlint --fix",
15+
"lint:tsgolint": "oxlint-tsgolint --fix",
16+
"lint:tsgolint2": "oxlint-tsgolint --fix",
17+
"lint:tsgolin2": "oxlint-tsgolint --fix",
18+
"lint:tsgolt2": "oxlint-tsgolint --fix",
19+
"lint:tsgint2": "oxlint-tsgolint --fix",
20+
"lint:tsolint2": "oxlint-tsgolint --fix",
21+
"lint:tgolint2": "oxlint-tsgolint --fix",
22+
"lint:sgolint2": "oxlint-tsgolint --fix",
23+
"lin:tsgolint2": "oxlint-tsgolint --fix",
24+
"linttsgolint2": "oxlint-tsgolint --fix",
25+
"lit:tsgolint2": "oxlint-tsgolint --fix",
26+
"lnt:tsgolint2": "oxlint-tsgolint --fix"
27+
},
1228
"dependencies": {
1329
"cross-env": "^10.1.0",
1430
"oxfmt": "0.26.0",

0 commit comments

Comments
 (0)