Skip to content

Commit b089bfe

Browse files
author
ComputelessComputer
committed
fix stale @ autocomplete dropdown rows when matches shrink
1 parent 2391d55 commit b089bfe

3 files changed

Lines changed: 87 additions & 69 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aipm"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
edition = "2021"
55

66
[dependencies]

src/main.rs

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ struct App {
292292

293293
esc_count: u8,
294294
esc_last: Instant,
295+
autocomplete_last_height: usize,
295296
}
296297

297298
struct TerminalGuard;
@@ -535,6 +536,7 @@ fn main() -> io::Result<()> {
535536
google_auth_rx: None,
536537
esc_count: 0,
537538
esc_last: Instant::now(),
539+
autocomplete_last_height: 0,
538540
};
539541

540542
if auto_archive_tasks(&mut app.tasks) {
@@ -4715,7 +4717,7 @@ fn render_tabs(stdout: &mut Stdout, app: &App, cols: u16) -> io::Result<()> {
47154717
Ok(())
47164718
}
47174719

4718-
fn render_input_bar(stdout: &mut Stdout, app: &App, cols: u16, rows: u16) -> io::Result<()> {
4720+
fn render_input_bar(stdout: &mut Stdout, app: &mut App, cols: u16, rows: u16) -> io::Result<()> {
47194721
let width = cols as usize;
47204722
let num_buckets = app.settings.buckets.len().max(1);
47214723
let (x_margin, _) = choose_layout(width, num_buckets);
@@ -4833,80 +4835,96 @@ fn render_input_bar(stdout: &mut Stdout, app: &App, cols: u16, rows: u16) -> io:
48334835
ResetColor
48344836
)?;
48354837

4836-
// @ autocomplete dropdown.
4838+
// @ and / autocomplete dropdown.
48374839
if app.focus == Focus::Input {
4840+
const MAX_SHOW: usize = 8;
48384841
let completions = at_completions(&app.tasks, &app.input, app.input_cursor);
4842+
let slash_comps = if completions.is_empty() {
4843+
slash_completions(&app.input, app.input_cursor)
4844+
} else {
4845+
Vec::new()
4846+
};
4847+
4848+
let current_height = if !completions.is_empty() {
4849+
completions.len().min(MAX_SHOW)
4850+
} else {
4851+
slash_comps.len().min(MAX_SHOW)
4852+
};
4853+
4854+
if current_height < app.autocomplete_last_height {
4855+
let blank = pad_to_width("", content_width);
4856+
for i in current_height..app.autocomplete_last_height {
4857+
let y_row = y_sep_top.saturating_sub(1 + i as u16);
4858+
queue!(stdout, MoveTo(x, y_row), Print(&blank))?;
4859+
}
4860+
}
4861+
app.autocomplete_last_height = current_height;
4862+
48394863
if !completions.is_empty() {
4840-
const MAX_SHOW: usize = 8;
4841-
let show = completions.len().min(MAX_SHOW);
4842-
if show > 0 {
4843-
let sel = app
4844-
.at_autocomplete_selected
4845-
.min(completions.len().saturating_sub(1));
4846-
let scroll = if sel >= show { sel - show + 1 } else { 0 };
4847-
for (draw_i, (short_id, title, bucket)) in
4848-
completions.iter().enumerate().skip(scroll).take(show)
4849-
{
4850-
let row_from_bottom = show - (draw_i - scroll) - 1;
4851-
let y_row = y_sep_top - 1 - row_from_bottom as u16;
4852-
let label = format!(" {} {} [{}]", short_id, title, bucket);
4853-
let padded = pad_to_width(&clamp_text(&label, content_width), content_width);
4854-
queue!(stdout, MoveTo(x, y_row))?;
4855-
if draw_i == sel {
4856-
queue!(
4857-
stdout,
4858-
SetForegroundColor(Color::Black),
4859-
SetBackgroundColor(Color::White),
4860-
Print(&padded),
4861-
ResetColor
4862-
)?;
4863-
} else {
4864-
queue!(
4865-
stdout,
4866-
SetForegroundColor(Color::White),
4867-
SetBackgroundColor(Color::DarkGrey),
4868-
Print(&padded),
4869-
ResetColor
4870-
)?;
4871-
}
4864+
let show = current_height;
4865+
let sel = app
4866+
.at_autocomplete_selected
4867+
.min(completions.len().saturating_sub(1));
4868+
let scroll = if sel >= show { sel - show + 1 } else { 0 };
4869+
for (draw_i, (short_id, title, bucket)) in
4870+
completions.iter().enumerate().skip(scroll).take(show)
4871+
{
4872+
let row_from_bottom = show - (draw_i - scroll) - 1;
4873+
let y_row = y_sep_top - 1 - row_from_bottom as u16;
4874+
let label = format!(" {} {} [{}]", short_id, title, bucket);
4875+
let padded = pad_to_width(&clamp_text(&label, content_width), content_width);
4876+
queue!(stdout, MoveTo(x, y_row))?;
4877+
if draw_i == sel {
4878+
queue!(
4879+
stdout,
4880+
SetForegroundColor(Color::Black),
4881+
SetBackgroundColor(Color::White),
4882+
Print(&padded),
4883+
ResetColor
4884+
)?;
4885+
} else {
4886+
queue!(
4887+
stdout,
4888+
SetForegroundColor(Color::White),
4889+
SetBackgroundColor(Color::DarkGrey),
4890+
Print(&padded),
4891+
ResetColor
4892+
)?;
48724893
}
48734894
}
4874-
} else {
4875-
let slash_comps = slash_completions(&app.input, app.input_cursor);
4876-
if !slash_comps.is_empty() {
4877-
const MAX_SHOW: usize = 8;
4878-
let show = slash_comps.len().min(MAX_SHOW);
4879-
let sel = app
4880-
.slash_autocomplete_selected
4881-
.min(slash_comps.len().saturating_sub(1));
4882-
let scroll = if sel >= show { sel - show + 1 } else { 0 };
4883-
for (draw_i, (cmd, desc)) in slash_comps.iter().enumerate().skip(scroll).take(show)
4884-
{
4885-
let row_from_bottom = show - (draw_i - scroll) - 1;
4886-
let y_row = y_sep_top - 1 - row_from_bottom as u16;
4887-
let label = format!(" /{} — {}", cmd, desc);
4888-
let padded = pad_to_width(&clamp_text(&label, content_width), content_width);
4889-
queue!(stdout, MoveTo(x, y_row))?;
4890-
if draw_i == sel {
4891-
queue!(
4892-
stdout,
4893-
SetForegroundColor(Color::Black),
4894-
SetBackgroundColor(Color::White),
4895-
Print(&padded),
4896-
ResetColor
4897-
)?;
4898-
} else {
4899-
queue!(
4900-
stdout,
4901-
SetForegroundColor(Color::White),
4902-
SetBackgroundColor(Color::DarkGrey),
4903-
Print(&padded),
4904-
ResetColor
4905-
)?;
4906-
}
4895+
} else if !slash_comps.is_empty() {
4896+
let show = current_height;
4897+
let sel = app
4898+
.slash_autocomplete_selected
4899+
.min(slash_comps.len().saturating_sub(1));
4900+
let scroll = if sel >= show { sel - show + 1 } else { 0 };
4901+
for (draw_i, (cmd, desc)) in slash_comps.iter().enumerate().skip(scroll).take(show) {
4902+
let row_from_bottom = show - (draw_i - scroll) - 1;
4903+
let y_row = y_sep_top - 1 - row_from_bottom as u16;
4904+
let label = format!(" /{} \u{2014} {}", cmd, desc);
4905+
let padded = pad_to_width(&clamp_text(&label, content_width), content_width);
4906+
queue!(stdout, MoveTo(x, y_row))?;
4907+
if draw_i == sel {
4908+
queue!(
4909+
stdout,
4910+
SetForegroundColor(Color::Black),
4911+
SetBackgroundColor(Color::White),
4912+
Print(&padded),
4913+
ResetColor
4914+
)?;
4915+
} else {
4916+
queue!(
4917+
stdout,
4918+
SetForegroundColor(Color::White),
4919+
SetBackgroundColor(Color::DarkGrey),
4920+
Print(&padded),
4921+
ResetColor
4922+
)?;
49074923
}
49084924
}
49094925
}
4926+
} else {
4927+
app.autocomplete_last_height = 0;
49104928
}
49114929

49124930
// Cursor.

0 commit comments

Comments
 (0)