Skip to content

Commit 4f67dad

Browse files
tmmampagent
andauthored
fix(zbugs-rune): step through the issue list with the arrow keys (#181)
Up and Down select the previous and next issue, as j and k do and as zbugs-swift's and zbugs-gpui's lists do. e2e.sh checks them. Amp-Thread-ID: https://ampcode.com/threads/T-d4c65674-78c3-4cc9-93bc-4a6a0b56f48d Co-authored-by: Amp <amp@ampcode.com>
1 parent 957fec6 commit 4f67dad

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

‎apps/zbugs-rune/README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ both), and Windows is next.
1717
app's list params),
1818
the issue list (virtual rows, paged as it scrolls, with a dot on issues
1919
changed since you looked, and Select to delete several; j and k step
20-
through it, as on the web), the issue with its Markdown, comments, and
21-
reactions, its assignee, visibility, notifications, and labels, and sheets
22-
to create, edit, and delete an issue, edit and delete comments, create
23-
a label, log in, and set the servers.
20+
through it, as on the web, and so do the arrow keys), the issue with its
21+
Markdown, comments, and reactions, its assignee, visibility,
22+
notifications, and labels, and sheets to create, edit, and delete an
23+
issue, edit and delete comments, create a label, log in, and set the
24+
servers.
2425
- `src/images.rs` fetches avatars and the images in issues and comments
2526
(`ureq`, over rustls) for Rune's image cache to decode, as the web app
2627
shows them.

‎apps/zbugs-rune/e2e.sh‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
# zbugs-rune against zbugs' backend, end to end: the app runs headless on
3-
# the wall clock (`--realtime`), opens an open issue, comments on it, reacts
3+
# the wall clock (`--realtime`), steps away from an open issue and back with
4+
# the arrow keys, then opens it, comments on it, reacts
45
# to it, labels it, closes it, edits the comment, creates a label for it,
56
# makes it internal, and unsubscribes from it, pressing its controls as a
67
# person would. Opening it marks it viewed. Then Postgres must have each
@@ -22,6 +23,25 @@ out=$(mktemp -d)
2223
issue=$(sql "select id from issue i where open and not exists
2324
(select 1 from comment c where c.\"issueID\" = i.id)
2425
order by length(description), \"shortID\" limit 1")
26+
27+
# First the arrow keys: down twice, up, then k must land back on the issue,
28+
# which the app saves as its selection. Before the view-state reset below,
29+
# as this run marks the issue viewed.
30+
mkdir -p "$out/arrows"
31+
printf '{"selection":"%s"}' "$issue" > "$out/arrows/settings.json"
32+
cat > "$out/arrows.json" <<EOF
33+
{"events": [
34+
{"t": 12.0, "type": "key", "name": "Down"},
35+
{"t": 12.3, "type": "key", "name": "Down"},
36+
{"t": 12.6, "type": "key", "name": "Up"},
37+
{"t": 12.9, "type": "key", "name": "k"}
38+
]}
39+
EOF
40+
ZBUGS_RUNE_DIR="$out/arrows" cargo run --locked --quiet -- --realtime \
41+
--script "$out/arrows.json" --at 13.5 --size 1180x760 >/dev/null
42+
arrows=$(node -e 'console.log(JSON.parse(require("fs").readFileSync(process.argv[1])).selection)' \
43+
"$out/arrows/settings.json")
44+
2545
# The label picker lists the issue's project's labels by name, bytewise.
2646
first_label=$(sql "select l.name from label l join issue i on i.\"projectID\" = l.\"projectID\"
2747
where i.id = '$issue' order by l.name collate \"C\" limit 1")
@@ -72,6 +92,7 @@ fail=0
7292
check() {
7393
if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAILED: $1: got '$2', want '$3'"; fail=1; fi
7494
}
95+
check "the arrow keys" "$arrows" "$issue"
7596
check "the comment, edited" \
7697
"$(sql "select count(*) from comment where \"issueID\" = '$issue' and body = '$body edited'")" 1
7798
check "the reaction" \

‎apps/zbugs-rune/src/main.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,9 +1130,10 @@ fn apply_issues(s: &mut App, rows: Vec<Issue>, result_type: ResultType, tx: &mut
11301130
}
11311131
}
11321132

1133-
/// Keys no control took: j and k step through the list, / starts a search,
1134-
/// as on the web, and Escape closes an open picker (Rune's popovers leave
1135-
/// Escape to the app).
1133+
/// Keys no control took: j and k (and the arrow keys, as zbugs-swift's and
1134+
/// zbugs-gpui's lists) step through the list, / starts a search, as on the
1135+
/// web, and Escape closes an open picker (Rune's popovers leave Escape to
1136+
/// the app).
11361137
fn on_key(s: &mut App, event: &rune::KeyEvent, tx: &mut Tx) -> bool {
11371138
if s.sheet.is_some()
11381139
|| s.confirm.is_some()
@@ -1144,6 +1145,8 @@ fn on_key(s: &mut App, event: &rune::KeyEvent, tx: &mut Tx) -> bool {
11441145
}
11451146
match &event.key {
11461147
rune::Key::Escape if s.picker.is_some() => s.picker = None,
1148+
rune::Key::Down => s.step(1, tx),
1149+
rune::Key::Up => s.step(-1, tx),
11471150
rune::Key::Text(t) if t == "j" => s.step(1, tx),
11481151
rune::Key::Text(t) if t == "k" => s.step(-1, tx),
11491152
rune::Key::Text(t) if t == "/" => s.search.focused = true,

0 commit comments

Comments
 (0)