add find messages
This commit is contained in:
@@ -49,9 +49,75 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
KeyCode::Char('f') if has_ctrl => {
|
||||
// Ctrl+F - поиск по сообщениям в открытом чате
|
||||
if app.selected_chat_id.is_some() && !app.is_pinned_mode() && !app.is_message_search_mode() {
|
||||
app.enter_message_search_mode();
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Режим поиска по сообщениям
|
||||
if app.is_message_search_mode() {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.exit_message_search_mode();
|
||||
}
|
||||
KeyCode::Up | KeyCode::Char('N') => {
|
||||
app.select_previous_search_result();
|
||||
}
|
||||
KeyCode::Down | KeyCode::Char('n') => {
|
||||
app.select_next_search_result();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// Перейти к выбранному сообщению
|
||||
if let Some(msg_id) = app.get_selected_search_result_id() {
|
||||
let msg_index = app.td_client.current_chat_messages
|
||||
.iter()
|
||||
.position(|m| m.id == msg_id);
|
||||
|
||||
if let Some(idx) = msg_index {
|
||||
let total = app.td_client.current_chat_messages.len();
|
||||
app.message_scroll_offset = total.saturating_sub(idx + 5);
|
||||
}
|
||||
app.exit_message_search_mode();
|
||||
}
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
app.message_search_query.pop();
|
||||
// Выполняем поиск при изменении запроса
|
||||
if let Some(chat_id) = app.get_selected_chat_id() {
|
||||
if !app.message_search_query.is_empty() {
|
||||
if let Ok(Ok(results)) = timeout(
|
||||
Duration::from_secs(3),
|
||||
app.td_client.search_messages(chat_id, &app.message_search_query)
|
||||
).await {
|
||||
app.set_search_results(results);
|
||||
}
|
||||
} else {
|
||||
app.set_search_results(Vec::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
app.message_search_query.push(c);
|
||||
// Выполняем поиск при изменении запроса
|
||||
if let Some(chat_id) = app.get_selected_chat_id() {
|
||||
if let Ok(Ok(results)) = timeout(
|
||||
Duration::from_secs(3),
|
||||
app.td_client.search_messages(chat_id, &app.message_search_query)
|
||||
).await {
|
||||
app.set_search_results(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Режим просмотра закреплённых сообщений
|
||||
if app.is_pinned_mode() {
|
||||
match key.code {
|
||||
|
||||
Reference in New Issue
Block a user