remove unecessary changes

This commit is contained in:
pap
2025-08-09 16:42:34 +01:00
parent e93ca9fa11
commit 194dc82c93
3 changed files with 12 additions and 55 deletions

View File

@@ -712,19 +712,21 @@ impl ChatComposer {
/// Synchronize `self.file_search_popup` with the current text in the textarea.
/// Note this is only called when self.active_popup is NOT Command.
fn sync_file_search_popup(&mut self) {
// Determine current query (may be empty if user just selected @file and hasn't typed yet).
let query_opt = Self::current_at_token(&self.textarea);
let Some(query) = query_opt else {
// Token removed end session.
self.active_popup = ActivePopup::None;
self.dismissed_file_popup_token = None;
return;
// Determine if there is an @token underneath the cursor.
let query = match Self::current_at_token(&self.textarea) {
Some(token) => token,
None => {
self.active_popup = ActivePopup::None;
self.dismissed_file_popup_token = None;
return;
}
};
// If user dismissed popup for this exact query, don't reopen until text changes.
if self.dismissed_file_popup_token.as_ref() == Some(&query) {
return;
}
if !query.is_empty() {
self.app_event_tx
.send(AppEvent::StartFileSearch(query.clone()));

View File

@@ -38,6 +38,7 @@ impl CommandPopup {
// shows the help for `/clear`.
let token = stripped.trim_start();
let cmd_token = token.split_whitespace().next().unwrap_or("");
// Update the filter keeping the original case (commands are all
// lower-case for now but this may change in the future).
self.command_filter = cmd_token.to_string();

View File

@@ -2,7 +2,6 @@ use codex_file_search::FileMatch;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::widgets::WidgetRef;
use std::fs;
use super::popup_consts::MAX_POPUP_ROWS;
use super::scroll_state::ScrollState;
@@ -26,16 +25,13 @@ pub(crate) struct FileSearchPopup {
impl FileSearchPopup {
pub(crate) fn new() -> Self {
// If pending_query is empty, pre-populate matches with files in current dir.
let mut popup = Self {
Self {
display_query: String::new(),
pending_query: String::new(),
waiting: true,
matches: Vec::new(),
state: ScrollState::new(),
};
popup.populate_current_dir_if_empty_query();
popup
}
}
/// Update the query and reset state to *waiting*.
@@ -56,12 +52,6 @@ impl FileSearchPopup {
self.matches.clear();
self.state.reset();
}
// If query is empty, show files in current directory.
if query.is_empty() {
self.populate_current_dir_if_empty_query();
self.waiting = false;
}
}
/// Put the popup into an "idle" state used for an empty query (just "@").
@@ -120,42 +110,6 @@ impl FileSearchPopup {
self.matches.len().clamp(1, MAX_POPUP_ROWS) as u16
}
/// Populate matches with files in the current directory if the query is empty.
fn populate_current_dir_if_empty_query(&mut self) {
if !self.pending_query.is_empty() {
return;
}
// Only populate if matches is empty (avoid overwriting search results).
if !self.matches.is_empty() {
return;
}
let mut entries: Vec<FileMatch> = Vec::new();
if let Ok(read_dir) = fs::read_dir(".") {
for entry in read_dir.flatten().take(MAX_POPUP_ROWS) {
if let Ok(file_type) = entry.file_type() {
// Skip hidden files (dotfiles) for a cleaner popup.
let file_name = entry.file_name();
let file_name_str = file_name.to_string_lossy();
if file_name_str.starts_with('.') {
continue;
}
// Only show files and directories (not symlinks, etc).
if file_type.is_file() || file_type.is_dir() {
entries.push(FileMatch {
path: file_name_str.to_string(),
indices: Some(Vec::new()), // No highlights for empty query.
score: 0,
});
}
}
}
}
self.matches = entries;
self.state.clamp_selection(self.matches.len());
self.state
.ensure_visible(self.matches.len(), self.matches.len().min(MAX_POPUP_ROWS));
}
}
impl WidgetRef for &FileSearchPopup {