From c9282c73f06e267731f24e090b4daa26b3a67f67 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:14:05 +0800 Subject: [PATCH] fix: keep the newest reported histfiles; bind the menu's run to cmd-enter - shell-histfiles is append-only and panes starting together append the same path; reading the first 32 lines let stale or duplicate entries hide every path reported later. Keep the newest 32 distinct ones. - secondary-enter is ctrl-enter off macOS, where the Ctrl+R menu only accepts on that chord. Bind cmd-enter, matching the menu's own key handler on every platform. --- src/terminal/history.rs | 28 ++++++++++++++++++++++++---- src/ui/keymap.rs | 4 +++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/terminal/history.rs b/src/terminal/history.rs index e9f1acb2..eb8f3fea 100644 --- a/src/terminal/history.rs +++ b/src/terminal/history.rs @@ -344,13 +344,20 @@ fn reported_history_files() -> Vec { fn parse_reported_history_files(text: &str) -> Vec { // The file is written from inside panes, so it is only a hint: a relative // path would resolve against this process's directory, and a list that - // grew without bound is not one worth reading in full. - text.lines() + // grew without bound is not one worth reading in full. It is only ever + // appended to, and panes starting together each append the same path, so + // the newest distinct paths are the ones kept. + let mut seen = HashSet::new(); + let mut files: Vec = text + .lines() + .rev() .map(str::trim) - .filter(|line| looks_absolute(line)) + .filter(|line| looks_absolute(line) && seen.insert(*line)) .take(32) .map(PathBuf::from) - .collect() + .collect(); + files.reverse(); + files } fn read_shell_history_files(mut files: Vec) -> Vec { @@ -734,6 +741,19 @@ mod tests { ); } + #[test] + fn reported_history_files_keep_the_newest_distinct_paths() { + let mut text = String::new(); + for i in 0..40 { + text.push_str(&format!("/old/{i}\n/dup\n")); + } + text.push_str("/new\n"); + let files = parse_reported_history_files(&text); + assert_eq!(files.len(), 32); + assert_eq!(files.last(), Some(&PathBuf::from("/new"))); + assert_eq!(files.iter().filter(|p| *p == Path::new("/dup")).count(), 1); + } + #[test] fn plain_bash_lines() { assert_eq!( diff --git a/src/ui/keymap.rs b/src/ui/keymap.rs index 56eb43b9..82d11252 100644 --- a/src/ui/keymap.rs +++ b/src/ui/keymap.rs @@ -56,8 +56,10 @@ fn fixed_bindings() -> Vec { // The Ctrl+R menu runs its selection on Cmd+Enter, which on macOS is // also `ToggleFullscreen`. Scoped to the open menu, it is deeper in // the dispatch path than the window binding and wins only there. + // `cmd`, not `secondary`: the menu's own key handler runs on the + // platform key everywhere, and Ctrl+Enter off macOS only accepts. KeyBinding::new( - "secondary-enter", + "cmd-enter", RunReverseSearchSelection, Some("Terminal && reverse_search"), ),