Skip to content

Commit 1a544fc

Browse files
committed
Compact shortcut badges and remove redundant diff hidden counts
1 parent 914c79e commit 1a544fc

9 files changed

Lines changed: 61 additions & 44 deletions

File tree

‎crates/jcode-tui/src/tui/app/tests/scroll_copy_02/part_01.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn test_local_error_copy_badge_shortcut_supported() {
66

77
let initial = render_and_snap(&app, &mut terminal);
88
assert!(
9-
initial.contains("[S]"),
9+
initial.contains("⇧S]"),
1010
"expected visible error copy badge: {}",
1111
initial
1212
);
@@ -44,7 +44,7 @@ fn test_clicking_copy_badge_copies_its_target() {
4444
let line = (0..area.width)
4545
.map(|col| buf[(col, row)].symbol())
4646
.collect::<String>();
47-
if let Some(byte) = line.find("[S]") {
47+
if let Some(byte) = line.find("⇧S]") {
4848
badge = Some((line[..byte].chars().count() as u16, row));
4949
break 'rows;
5050
}
@@ -77,7 +77,7 @@ fn test_local_tool_error_copy_badge_shortcut_supported() {
7777

7878
let initial = render_and_snap(&app, &mut terminal);
7979
assert!(
80-
initial.contains("[S]"),
80+
initial.contains("⇧S]"),
8181
"expected visible tool error copy badge: {}",
8282
initial
8383
);
@@ -108,7 +108,7 @@ fn test_local_tool_failed_output_copy_badge_shortcut_supported() {
108108

109109
let initial = render_and_snap(&app, &mut terminal);
110110
assert!(
111-
initial.contains("[S]"),
111+
initial.contains("⇧S]"),
112112
"expected visible failed tool output copy badge: {}",
113113
initial
114114
);
@@ -141,7 +141,7 @@ fn test_local_blockquote_copy_badge_shortcut_supported() {
141141

142142
let initial = render_and_snap(&app, &mut terminal);
143143
assert!(
144-
initial.contains("[S]"),
144+
initial.contains("⇧S]"),
145145
"expected visible blockquote copy badge: {}",
146146
initial
147147
);
@@ -200,7 +200,7 @@ fn test_copy_selection_select_all_uses_rendered_chat_text_without_copy_badges()
200200
assert!(selected.contains("fn main() {"));
201201
assert!(selected.contains("println!(\"hello\");"));
202202
assert!(
203-
!selected.contains("[Alt]") && !selected.contains("[⌥]"),
203+
!selected.contains("[Alt⇧") && !selected.contains("[⌥⇧"),
204204
"selection should use chat text, not copy badge chrome: {}",
205205
selected
206206
);

‎crates/jcode-tui/src/tui/app/tests/scroll_copy_02/part_02.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ fn test_unicode_math_copy_badge_copies_latex_to_clipboard() {
17421742
let clipboard = CapturedClipboard::new();
17431743
let (mut app, mut terminal) = create_math_copy_test_app();
17441744
let screen = render_and_snap(&app, &mut terminal);
1745-
assert!(screen.contains("[S]"), "math frame should get a badge: {screen}");
1745+
assert!(screen.contains("⇧S]"), "math frame should get a badge: {screen}");
17461746

17471747
app.handle_key(KeyCode::Char('S'), KeyModifiers::ALT)
17481748
.unwrap();

‎crates/jcode-tui/src/tui/ui_inline_image.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ fn fit_rows(width: u32, height: u32, chat_width: u16, viewport_height: u16) -> u
909909

910910
/// Build the dim label line shown above an inline image, e.g.
911911
/// ` screenshot.png 1920×1080`, with a trailing show/hide badge
912-
/// (`[Alt] [⇧] [I] hide` / `[Alt] [⇧] [I] show image`) so the toggle is
912+
/// (`[Alt⇧I] hide` / `[Alt⇧I] show image`) so the toggle is
913913
/// discoverable right where the image renders. The line is kept deliberately
914914
/// short so it fits on one row; there is no visible expand badge, but clicking
915915
/// the rendered image body still cycles the per-image size
@@ -928,11 +928,9 @@ pub(crate) fn image_label_line(
928928
};
929929
let dim = Style::default().add_modifier(Modifier::DIM);
930930
let prefix = Line::from(vec![Span::styled(" ", dim), Span::styled(label, dim)]);
931-
let mut suffix = vec![
932-
Span::raw(" "),
933-
Span::styled(super::viewport::copy_badge_alt_badge(), dim),
934-
Span::styled(" [⇧] [I] ", dim),
935-
];
931+
let mut suffix = vec![Span::raw(" ")];
932+
suffix.extend(super::viewport::shortcut_badge_spans('I', dim, dim, dim));
933+
suffix.push(Span::raw(" "));
936934
if images_visible {
937935
suffix.push(Span::styled("hide", dim));
938936
} else {
@@ -1279,7 +1277,7 @@ mod tests {
12791277
fn visible_label_line_advertises_hide_badge() {
12801278
let line = image_label_line(&item(600, 400), 80, true, ImageExpandLevel::Fit);
12811279
let text = jcode_tui_render::line_plain_text(&line);
1282-
assert!(text.contains("[⇧] [I]"), "badge keys missing: {text:?}");
1280+
assert!(text.contains("⇧I]"), "badge keys missing: {text:?}");
12831281
assert!(text.contains("hide"), "hide hint missing: {text:?}");
12841282
}
12851283

‎crates/jcode-tui/src/tui/ui_input.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,15 +1682,10 @@ pub(super) fn build_notification_spans(app: &dyn TuiState) -> Vec<Span<'static>>
16821682
};
16831683
spans.push(Span::styled(feedback_text, feedback_style));
16841684
}
1685-
spans.push(Span::styled(
1686-
super::viewport::copy_badge_alt_badge(),
1685+
spans.extend(super::viewport::shortcut_badge_spans(
1686+
key,
16871687
alt_style,
1688-
));
1689-
spans.push(Span::raw(" "));
1690-
spans.push(Span::styled("[⇧]", shift_style));
1691-
spans.push(Span::raw(" "));
1692-
spans.push(Span::styled(
1693-
format!("[{}]", key.to_ascii_uppercase()),
1688+
shift_style,
16941689
key_style,
16951690
));
16961691
}

‎crates/jcode-tui/src/tui/ui_messages.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,11 +4706,7 @@ pub(crate) fn render_tool_message(
47064706
lines.push(Line::from(spans).alignment(ratatui::layout::Alignment::Left));
47074707
}
47084708

4709-
let footer = if truncated {
4710-
format!("{pad_str}╰─ {} hidden", total_changes - MAX_DIFF_LINES)
4711-
} else {
4712-
format!("{pad_str}╰─")
4713-
};
4709+
let footer = format!("{pad_str}╰─");
47144710
lines.push(
47154711
super::truncate_line_with_ellipsis_to_width(
47164712
&Line::from(Span::styled(footer, Style::default().fg(dim_color()))),

‎crates/jcode-tui/src/tui/ui_messages/tests.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,8 @@ fn render_tool_message_inline_mode_truncates_large_diffs() {
33623362
assert!(!extract_line_text(&lines[0]).contains("+7"));
33633363
assert!(!plain.contains("total"));
33643364
let footer = lines.last().unwrap();
3365-
assert_eq!(extract_line_text(footer), "╰─ 2 hidden");
3365+
assert_eq!(extract_line_text(footer), "╰─");
3366+
assert!(!plain.contains("hidden"), "plain={plain}");
33663367
let header = &lines[1];
33673368
assert!(extract_line_text(header).starts_with("╭─ diff · +7 -7 · "));
33683369
assert!(

‎crates/jcode-tui/src/tui/ui_tests/basic/input_layout.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ fn test_copy_badge_reserves_right_margin_for_info_widgets() {
365365
let _env = crate::storage::lock_test_env();
366366
let _lock = viewport_snapshot_test_lock();
367367
// Construct the rendered text independently of the reservation helper.
368-
let shortcut = format!(" [{}] [⇧] [A]", viewport::copy_badge_alt_label());
368+
let shortcut = format!(" [{}⇧A]", viewport::copy_badge_alt_label());
369369
let shortcut_width = unicode_width::UnicodeWidthStr::width(shortcut.as_str());
370370
let mut margins = info_widget::Margins {
371371
right_widths: vec![30, 30, 30],
@@ -421,7 +421,7 @@ fn test_expand_badge_reserves_right_margin_for_info_widgets() {
421421
fn test_copy_badge_truncates_full_width_line_before_appending_shortcut() {
422422
let _env = crate::storage::lock_test_env();
423423
let _lock = viewport_snapshot_test_lock();
424-
let shortcut = format!(" [{}] [⇧] [A]", viewport::copy_badge_alt_label());
424+
let shortcut = format!(" [{}⇧A]", viewport::copy_badge_alt_label());
425425
let shortcut_width = unicode_width::UnicodeWidthStr::width(shortcut.as_str());
426426
let copy_badge_ui = crate::tui::app::CopyBadgeUiState::default();
427427
let reserved = copy_badge_reserved_width('a', &copy_badge_ui, Instant::now());
@@ -445,7 +445,7 @@ fn test_copy_badge_line_prefers_row_with_free_width_over_truncation() {
445445
let full = Line::from("│ ".to_string() + &"x".repeat(60));
446446
let short = Line::from("│ short".to_string());
447447
let visible_lines = vec![full, short];
448-
let reserved = 14usize; // " [Alt] [⇧] [S]"
448+
let reserved = 8usize; // " [Alt⇧S]"
449449

450450
let picked = pick_copy_badge_line(0, 0, 2, 0, 2, &visible_lines, 62, reserved);
451451
assert_eq!(picked, 1, "badge should move to the line with free width");

‎crates/jcode-tui/src/tui/ui_viewport.rs‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,26 @@ fn copy_badge_alt_label_from_config(configured: &str) -> String {
4141
}
4242
}
4343

44-
pub(crate) fn copy_badge_alt_badge() -> String {
45-
format!("[{}]", copy_badge_alt_label())
44+
pub(crate) fn shortcut_badge_spans(
45+
key: char,
46+
alt_style: Style,
47+
shift_style: Style,
48+
key_style: Style,
49+
) -> [Span<'static>; 5] {
50+
let dim = Style::default().fg(dim_color());
51+
[
52+
Span::styled("[", dim),
53+
Span::styled(copy_badge_alt_label(), alt_style),
54+
Span::styled("⇧", shift_style),
55+
Span::styled(key.to_ascii_uppercase().to_string(), key_style),
56+
Span::styled("]", dim),
57+
]
4658
}
4759

4860
fn copy_badge_shortcut_width(key_label: &str) -> usize {
4961
// Includes the single separator space rendered between the row content and
5062
// the first badge.
51-
UnicodeWidthStr::width(format!(" {} [⇧] [{key_label}]", copy_badge_alt_badge()).as_str())
63+
UnicodeWidthStr::width(format!(" [{}⇧{key_label}]", copy_badge_alt_label()).as_str())
5264
}
5365

5466
/// Display width reserved for the compact inline expand-edit badge (`[Alt⇧E] …`).
@@ -923,14 +935,7 @@ pub(super) fn draw_messages(
923935
let shortcut_start = line.width();
924936

925937
line.spans
926-
.push(Span::styled(copy_badge_alt_badge(), alt_style));
927-
line.spans.push(Span::raw(" "));
928-
line.spans.push(Span::styled("[⇧]", shift_style));
929-
line.spans.push(Span::raw(" "));
930-
line.spans.push(Span::styled(
931-
format!("[{}]", key.to_ascii_uppercase()),
932-
key_style,
933-
));
938+
.extend(shortcut_badge_spans(key, alt_style, shift_style, key_style));
934939

935940
let final_width = line.width();
936941
let aligned_x = match line.alignment.unwrap_or(Alignment::Left) {

‎crates/jcode-tui/src/tui/ui_viewport_tests.rs‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,36 @@ fn compact_expand_badge_reserves_exact_display_cells() {
162162
for suffix in [" expand", " ✓ Expanded"] {
163163
let rendered = format!(" [{}⇧E]{suffix}", super::copy_badge_alt_label());
164164
assert_eq!(super::expand_badge_reserved_width(suffix), rendered.width());
165-
let previous = format!(" {} [⇧] [E]{suffix}", super::copy_badge_alt_badge());
165+
let previous = format!(" [{}] [⇧] [E]{suffix}", super::copy_badge_alt_label());
166166
assert!(rendered.width() < previous.width());
167167
}
168168
}
169169

170+
#[test]
171+
fn compact_shortcut_badge_matches_reserved_width_and_preserves_styles() {
172+
use ratatui::{
173+
style::{Color, Style},
174+
text::Line,
175+
};
176+
let alt = Style::default().fg(Color::Yellow);
177+
let shift = Style::default().fg(Color::Green);
178+
let key = Style::default().fg(Color::Blue);
179+
let spans = super::shortcut_badge_spans('a', alt, shift, key);
180+
assert_chrome_has_explicit_foregrounds(&spans);
181+
assert_eq!(spans[1].style, alt);
182+
assert_eq!(spans[2].style, shift);
183+
assert_eq!(spans[3].style, key);
184+
let line = Line::from(spans.to_vec());
185+
assert_eq!(
186+
line.to_string(),
187+
format!("[{}⇧A]", super::copy_badge_alt_label())
188+
);
189+
assert_eq!(line.width() + 1, super::copy_badge_shortcut_width("A"));
190+
}
191+
170192
#[test]
171193
fn exact_width_expand_badge_leaves_no_content_or_ellipsis() {
172-
let mut line = ratatui::text::Line::from("╰─ 28 hidden");
194+
let mut line = ratatui::text::Line::from("╰─");
173195
super::truncate_line_for_copy_badge(&mut line, 0);
174196
assert_eq!(line.width(), 0);
175197
assert!(line.spans.is_empty());

0 commit comments

Comments
 (0)