(
&mut self,
input: &str,
cursor: usize,
commands: &'static [CommandSpec],
)
| 37 | } |
| 38 | |
| 39 | pub fn update_with_commands( |
| 40 | &mut self, |
| 41 | input: &str, |
| 42 | cursor: usize, |
| 43 | commands: &'static [CommandSpec], |
| 44 | ) { |
| 45 | if self.suppressed && input == self.last_input { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | if self.suppressed && input != self.last_input { |
| 50 | self.suppressed = false; |
| 51 | } |
| 52 | |
| 53 | self.last_input = input.to_string(); |
| 54 | |
| 55 | if !input.starts_with('/') || !self.cursor_in_command(input, cursor) { |
| 56 | self.hide(); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | let query = input.split_whitespace().next().unwrap_or(""); |
| 61 | if query == "/" { |
| 62 | self.items = commands.iter().collect(); |
| 63 | } else { |
| 64 | self.items = match_substring_in(query, commands); |
| 65 | } |
| 66 | self.items.sort_by_key(|spec| spec.name); |
| 67 | |
| 68 | self.visible = !self.items.is_empty(); |
| 69 | if self.visible { |
| 70 | let selected = self.list_state.selected().unwrap_or(0); |
| 71 | let clamped = selected.min(self.items.len().saturating_sub(1)); |
| 72 | self.list_state.select(Some(clamped)); |
| 73 | } else { |
| 74 | self.list_state.select(None); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | pub fn is_visible(&self) -> bool { |
| 79 | self.visible |
no test coverage detected