ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
feat: search files trigger via @
fynnfluegge9b41415901f8
diff --git a/src/tui/app.rs b/src/tui/app.rsindex d697166..0c423e0 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -5,6 +5,7 @@ use crossterm::{terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},};use ratatui::{prelude::*, widgets::*};+use std::collections::HashSet;use std::io::{self, Stdout};use std::path::{Path, PathBuf};use std::sync::{mpsc, Arc};@@ -71,6 +72,8 @@ struct AppState {shell_popup: Option<ShellPopup>,// File search dropdownfile_search: Option<FileSearchState>,+ // File paths inserted via file search (for highlighting)+ highlighted_file_paths: HashSet<String>,// Task search popuptask_search: Option<TaskSearchState>,// PR creation confirmation popup@@ -164,7 +167,8 @@ struct FileSearchState {pattern: String,matches: Vec<String>,selected: usize,- start_pos: usize, // Position in input_buffer where # was typed+ start_pos: usize, // Position in input_buffer where trigger was typed+ trigger_char: char, // The character that triggered the search (# or @)}/// State for delete confirmation popup@@ -272,6 +276,7 @@ impl App {show_project_list: false,shell_popup: None,file_search: None,+ highlighted_file_paths: HashSet::new(),task_search: None,pr_confirm_popup: None,review_to_running_task_id: None,@@ -574,7 +579,9 @@ impl App {let (before_cursor, after_cursor) = state.input_buffer.split_at(state.input_cursor.min(state.input_buffer.len()));- let content = if state.input_mode == InputMode::InputDescription {+ let text_color = hex_to_color(&state.config.theme.color_text);+ let highlight_color = hex_to_color(&state.config.theme.color_accent);+ let full_text = if state.input_mode == InputMode::InputDescription {format!("Title: {}\n\n{}{}β{}",state.pending_task_title,@@ -586,8 +593,14 @@ impl App {format!("{}{}β{}", label, before_cursor, after_cursor)};- let input = Paragraph::new(content)- .style(Style::default().fg(hex_to_color(&state.config.theme.color_text)))+ let styled_text = if state.input_mode == InputMode::InputDescription && !state.highlighted_file_paths.is_empty() {+ build_highlighted_text(&full_text, &state.highlighted_file_paths, text_color, highlight_color)+ } else {+ Text::raw(full_text)+ };++ let input = Paragraph::new(styled_text)+ .style(Style::default().fg(text_color)).wrap(Wrap { trim: false }).block(Block::default()@@ -1292,7 +1305,7 @@ impl App {AppMode::Project(_) => {match self.state.input_mode {InputMode::Normal => self.handle_normal_key(key.code),- InputMode::InputTitle => self.handle_title_input(key.code),+ InputMode::InputTitle => self.handle_title_input(key),InputMode::InputDescription => self.handle_description_input(key),}}@@ -1861,8 +1874,9 @@ impl App {Ok(())}- fn handle_title_input(&mut self, key: KeyCode) -> Result<()> {- match key {+ fn handle_title_input(&mut self, key: crossterm::event::KeyEvent) -> Result<()> {+ let has_alt = key.modifiers.contains(crossterm::event::KeyModifiers::ALT);+ match key.code {KeyCode::Esc => {self.state.input_mode = InputMode::Normal;self.state.input_buffer.clear();@@ -1894,6 +1908,19 @@ impl App {self.state.input_mode = InputMode::InputDescription;}}+ KeyCode::Left if has_alt => {+ self.state.input_cursor = word_boundary_left(&self.state.input_buffer, self.state.input_cursor);+ }+ KeyCode::Right if has_alt => {+ self.state.input_cursor = word_boundary_right(&self.state.input_buffer, self.state.input_cursor);+ }+ // macOS: Option+Left/Right sends Alt+b / Alt+f+ KeyCode::Char('b') if has_alt => {+ self.state.input_cursor = word_boundary_left(&self.state.input_buffer, self.state.input_cursor);+ }+ KeyCode::Char('f') if has_alt => {+ self.state.input_cursor = word_boundary_right(&self.state.input_buffer, self.state.input_cursor);+ }KeyCode::Left => {if self.state.input_cursor > 0 {self.state.input_cursor -= 1;@@ -1941,13 +1968,14 @@ impl App {KeyCode::Enter | KeyCode::Tab => {// Select current matchif let Some(selected_file) = search.matches.get(search.selected).cloned() {- // Replace #pattern with the selected file path, preserving text after- let pattern_end = search.start_pos + 1 + search.pattern.len(); // +1 for #+ // Replace trigger+pattern with the selected file path, preserving text after+ let pattern_end = search.start_pos + 1 + search.pattern.len(); // +1 for trigger charlet suffix = self.state.input_buffer[pattern_end..].to_string();self.state.input_buffer.truncate(search.start_pos);self.state.input_buffer.push_str(&selected_file);self.state.input_cursor = self.state.input_buffer.len();self.state.input_buffer.push_str(&suffix);+ self.state.highlighted_file_paths.insert(selected_file);}self.state.file_search = None;}@@ -1974,7 +2002,7 @@ impl App {KeyCode::Backspace => {if search.pattern.is_empty() {// Cancel search if pattern is empty- self.state.input_buffer.pop(); // Remove the #+ self.state.input_buffer.pop(); // Remove the trigger charself.state.input_cursor = self.state.input_cursor.saturating_sub(1);self.state.file_search = None;} else {@@ -2002,6 +2030,7 @@ impl App {self.state.input_cursor = 0;self.state.pending_task_title.clear();self.state.editing_task_id = None;+ self.state.highlighted_file_paths.clear();}KeyCode::Enter => {// Check if line ends with backslash for line continuation@@ -2018,8 +2047,22 @@ impl App {self.state.input_cursor = 0;self.state.pending_task_title.clear();self.state.editing_task_id = None;+ self.state.highlighted_file_paths.clear();}}+ KeyCode::Left if key.modifiers.contains(crossterm::event::KeyModifiers::ALT) => {+ self.state.input_cursor = word_boundary_left(&self.state.input_buffer, self.state.input_cursor);+ }+ KeyCode::Right if key.modifiers.contains(crossterm::event::KeyModifiers::ALT) => {+ self.state.input_cursor = word_boundary_right(&self.state.input_buffer, self.state.input_cursor);+ }+ // macOS: Option+Left/Right sends Alt+b / Alt+f+ KeyCode::Char('b') if key.modifiers.contains(crossterm::event::KeyModifiers::ALT) => {+ self.state.input_cursor = word_boundary_left(&self.state.input_buffer, self.state.input_cursor);+ }+ KeyCode::Char('f') if key.modifiers.contains(crossterm::event::KeyModifiers::ALT) => {+ self.state.input_cursor = word_boundary_right(&self.state.input_buffer, self.state.input_cursor);+ }KeyCode::Left => {if self.state.input_cursor > 0 {self.state.input_cursor -= 1;@@ -2047,16 +2090,18 @@ impl App {self.state.input_buffer.remove(self.state.input_cursor);}}- KeyCode::Char('#') => {+ KeyCode::Char('#') | KeyCode::Char('@') => {// Start file search at cursor position+ let trigger = if let KeyCode::Char(c) = key.code { c } else { '#' };let start_pos = self.state.input_cursor;- self.state.input_buffer.insert(self.state.input_cursor, '#');+ self.state.input_buffer.insert(self.state.input_cursor, trigger);self.state.input_cursor += 1;self.state.file_search = Some(FileSearchState {pattern: String::new(),matches: vec![],selected: 0,start_pos,+ trigger_char: trigger,});self.update_file_search_matches();}@@ -2945,6 +2990,89 @@ fn parse_sgr(seq: &str, mut style: Style) -> Style {style}+/// Find the previous word boundary (for Option+Left)+fn word_boundary_left(s: &str, pos: usize) -> usize {+ if pos == 0 {+ return 0;+ }+ let bytes = s.as_bytes();+ let mut i = pos - 1;+ // Skip whitespace/punctuation+ while i > 0 && !bytes[i].is_ascii_alphanumeric() {+ i -= 1;+ }+ // Skip word characters+ while i > 0 && bytes[i - 1].is_ascii_alphanumeric() {+ i -= 1;+ }+ i+}++/// Find the next word boundary (for Option+Right)+fn word_boundary_right(s: &str, pos: usize) -> usize {+ let len = s.len();+ if pos >= len {+ return len;+ }+ let bytes = s.as_bytes();+ let mut i = pos;+ // Skip current word characters+ while i < len && bytes[i].is_ascii_alphanumeric() {+ i += 1;+ }+ // Skip whitespace/punctuation+ while i < len && !bytes[i].is_ascii_alphanumeric() {+ i += 1;+ }+ i+}++/// Build styled Text with highlighted file paths+fn build_highlighted_text<'a>(+ text: &str,+ file_paths: &HashSet<String>,+ text_color: Color,+ highlight_color: Color,+) -> Text<'a> {+ let normal_style = Style::default().fg(text_color);+ let highlight_style = Style::default().fg(highlight_color).bold();++ let lines: Vec<Line> = text+ .split('\n')+ .map(|line| {+ let mut spans: Vec<Span> = Vec::new();+ let mut remaining = line;++ while !remaining.is_empty() {+ // Find the earliest file path match in the remaining text+ let mut earliest: Option<(usize, &str)> = None;+ for path in file_paths {+ if let Some(pos) = remaining.find(path.as_str()) {+ if earliest.is_none() || pos < earliest.unwrap().0 {+ earliest = Some((pos, path.as_str()));+ }+ }+ }++ if let Some((pos, path)) = earliest {+ if pos > 0 {+ spans.push(Span::styled(remaining[..pos].to_string(), normal_style));+ }+ spans.push(Span::styled(path.to_string(), highlight_style));+ remaining = &remaining[pos + path.len()..];+ } else {+ spans.push(Span::styled(remaining.to_string(), normal_style));+ break;+ }+ }++ Line::from(spans)+ })+ .collect();++ Text::from(lines)+}+/// Fuzzy find files in a directory (respects .gitignore)fn fuzzy_find_files(project_path: &Path, pattern: &str, max_results: usize, git_ops: &dyn GitOperations) -> Vec<String> {// Use git ls-files to get tracked files (respects .gitignore)diff --git a/src/tui/app_tests.rs b/src/tui/app_tests.rsindex e8ab573..7f8aa4c 100644--- a/src/tui/app_tests.rs+++ b/src/tui/app_tests.rs@@ -1048,3 +1048,201 @@ fn test_collect_task_diff_only_unstaged() {assert!(!result.contains("Staged Changes"));assert!(!result.contains("Untracked Files"));}++// =============================================================================+// Tests for build_highlighted_text+// =============================================================================++/// Test build_highlighted_text with no file paths produces plain text+#[test]+fn test_build_highlighted_text_no_paths() {+ let paths = HashSet::new();+ let text = build_highlighted_text("hello world", &paths, Color::White, Color::Cyan);+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 1);+ assert_eq!(lines[0].spans.len(), 1);+ assert_eq!(lines[0].spans[0].content, "hello world");+}++/// Test build_highlighted_text highlights a single file path+#[test]+fn test_build_highlighted_text_single_path() {+ let mut paths = HashSet::new();+ paths.insert("src/main.rs".to_string());+ let text = build_highlighted_text(+ "Please edit src/main.rs for me",+ &paths,+ Color::White,+ Color::Cyan,+ );+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 1);+ assert_eq!(lines[0].spans.len(), 3);+ assert_eq!(lines[0].spans[0].content, "Please edit ");+ assert_eq!(lines[0].spans[1].content, "src/main.rs");+ assert_eq!(lines[0].spans[2].content, " for me");+ // The highlighted span should be bold+ assert!(lines[0].spans[1].style.add_modifier.contains(Modifier::BOLD));+}++/// Test build_highlighted_text with multiple file paths on one line+#[test]+fn test_build_highlighted_text_multiple_paths() {+ let mut paths = HashSet::new();+ paths.insert("a.rs".to_string());+ paths.insert("b.rs".to_string());+ let text = build_highlighted_text("fix a.rs and b.rs", &paths, Color::White, Color::Cyan);+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 1);+ // Should be: "fix " | "a.rs" | " and " | "b.rs"+ assert_eq!(lines[0].spans.len(), 4);+ assert_eq!(lines[0].spans[1].content, "a.rs");+ assert_eq!(lines[0].spans[3].content, "b.rs");+}++/// Test build_highlighted_text with multiline input+#[test]+fn test_build_highlighted_text_multiline() {+ let mut paths = HashSet::new();+ paths.insert("app.rs".to_string());+ let text = build_highlighted_text("line1\nfix app.rs\nline3", &paths, Color::White, Color::Cyan);+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 3);+ // First line: no highlight+ assert_eq!(lines[0].spans.len(), 1);+ assert_eq!(lines[0].spans[0].content, "line1");+ // Second line: has highlight+ assert_eq!(lines[1].spans.len(), 2);+ assert_eq!(lines[1].spans[0].content, "fix ");+ assert_eq!(lines[1].spans[1].content, "app.rs");+ // Third line: no highlight+ assert_eq!(lines[2].spans.len(), 1);+ assert_eq!(lines[2].spans[0].content, "line3");+}++/// Test build_highlighted_text when path is at the start of line+#[test]+fn test_build_highlighted_text_path_at_start() {+ let mut paths = HashSet::new();+ paths.insert("src/lib.rs".to_string());+ let text = build_highlighted_text("src/lib.rs is important", &paths, Color::White, Color::Cyan);+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 1);+ assert_eq!(lines[0].spans.len(), 2);+ assert_eq!(lines[0].spans[0].content, "src/lib.rs");+ assert_eq!(lines[0].spans[1].content, " is important");+}++/// Test build_highlighted_text when path is the entire line+#[test]+fn test_build_highlighted_text_path_is_entire_line() {+ let mut paths = HashSet::new();+ paths.insert("Cargo.toml".to_string());+ let text = build_highlighted_text("Cargo.toml", &paths, Color::White, Color::Cyan);+ let lines: Vec<&Line> = text.lines.iter().collect();+ assert_eq!(lines.len(), 1);+ assert_eq!(lines[0].spans.len(), 1);+ assert_eq!(lines[0].spans[0].content, "Cargo.toml");+ assert!(lines[0].spans[0].style.add_modifier.contains(Modifier::BOLD));+}++// =============================================================================+// Tests for word_boundary_left / word_boundary_right+// =============================================================================++/// Test word_boundary_left from end of string+#[test]+fn test_word_boundary_left_from_end() {+ assert_eq!(word_boundary_left("hello world", 11), 6);+}++/// Test word_boundary_left skips to previous word+#[test]+fn test_word_boundary_left_between_words() {+ assert_eq!(word_boundary_left("hello world", 6), 0);+}++/// Test word_boundary_left from middle of word+#[test]+fn test_word_boundary_left_mid_word() {+ assert_eq!(word_boundary_left("hello world", 8), 6);+}++/// Test word_boundary_left at start stays at 0+#[test]+fn test_word_boundary_left_at_start() {+ assert_eq!(word_boundary_left("hello", 0), 0);+}++/// Test word_boundary_left with multiple spaces+#[test]+fn test_word_boundary_left_multiple_spaces() {+ assert_eq!(word_boundary_left("hello world", 13), 8);+}++/// Test word_boundary_left with path separators+#[test]+fn test_word_boundary_left_path() {+ // From end of "src/main.rs", should jump back over "rs"+ assert_eq!(word_boundary_left("src/main.rs", 11), 9);+}++/// Test word_boundary_right from start of string+#[test]+fn test_word_boundary_right_from_start() {+ assert_eq!(word_boundary_right("hello world", 0), 6);+}++/// Test word_boundary_right from space between words+#[test]+fn test_word_boundary_right_from_space() {+ assert_eq!(word_boundary_right("hello world", 5), 6);+}++/// Test word_boundary_right from middle of word+#[test]+fn test_word_boundary_right_mid_word() {+ assert_eq!(word_boundary_right("hello world", 3), 6);+}++/// Test word_boundary_right at end stays at end+#[test]+fn test_word_boundary_right_at_end() {+ assert_eq!(word_boundary_right("hello", 5), 5);+}++/// Test word_boundary_right with multiple spaces+#[test]+fn test_word_boundary_right_multiple_spaces() {+ assert_eq!(word_boundary_right("hello world", 0), 8);+}++/// Test word_boundary_right with path separators+#[test]+fn test_word_boundary_right_path() {+ // From start of "src/main.rs", should jump over "src" then the separator+ assert_eq!(word_boundary_right("src/main.rs", 0), 4);+}++/// Test word_boundary_left with empty string+#[test]+fn test_word_boundary_left_empty() {+ assert_eq!(word_boundary_left("", 0), 0);+}++/// Test word_boundary_right with empty string+#[test]+fn test_word_boundary_right_empty() {+ assert_eq!(word_boundary_right("", 0), 0);+}++/// Test word_boundary roundtrip: jumping right then left returns close to start+#[test]+fn test_word_boundary_roundtrip() {+ let s = "hello world foo";+ let pos = word_boundary_right(s, 0); // -> 6 (start of "world")+ let pos = word_boundary_right(s, pos); // -> 12 (start of "foo")+ let pos = word_boundary_left(s, pos); // -> 6 (start of "world")+ let pos = word_boundary_left(s, pos); // -> 0 (start of "hello")+ assert_eq!(pos, 0);+}