BlueGit

ict rusty-teams

fix(search): Ctrl+K no longer blocks typing on the local message search

- Local full-text search runs in the background with the same generation check as the server search
- Snippets are computed only for the shown hits, not for every match of a short prefix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-16 · 2 weeks ago

Hash
ea2c96e77b2c87241e4b0ded7342ad7462d63cde
Parent
c430d14f
2 files changed +57 −22
crates/app/src/views/switcher.rs +42 −18
@@ -260,32 +260,56 @@ impl Switcher {
260 260 self.results = fuzzy::rank(query, &self.candidates, limit);
261 261 self.results
262 262 .sort_by_key(|candidate| candidate.group() != "Chats");
263 self.local_messages = if wants_messages {
264 let hits = self
265 .app
266 .read(cx)
267 .store
268 .search_messages(query, None, MAX_MESSAGE_RESULTS)
269 .unwrap_or_default();
270 let now = Local::now();
271 message_results(
272 hits,
273 &self.conversations,
274 now.date_naive(),
275 app_base::format::Zone::Local,
276 )
277 } else {
278 Vec::new()
279 };
280 self.messages = self.local_messages.clone();
263 self.local_messages.clear();
264 self.messages.clear();
281 265 self.people.clear();
282 266 self.highlighted = 0;
283 267 self.generation += 1;
268 if wants_messages {
269 self.schedule_local_search(query.to_owned(), cx);
270 }
284 271 if query.trim().chars().count() >= MIN_SERVER_QUERY_CHARS {
285 272 self.schedule_server_search(query.trim().to_owned(), cx);
286 273 }
287 274 }
288 275
276 fn schedule_local_search(&mut self, query: String, cx: &mut Context<Self>) {
277 let store = self.app.read(cx).store.clone();
278 let generation = self.generation;
279 cx.spawn(async move |this, cx| {
280 let hits = cx
281 .background_spawn(async move {
282 store
283 .search_messages(&query, None, MAX_MESSAGE_RESULTS)
284 .unwrap_or_default()
285 })
286 .await;
287 this.update(cx, |switcher, cx| {
288 switcher.apply_local(generation, hits, cx)
289 })
290 .ok();
291 })
292 .detach();
293 }
294
295 fn apply_local(&mut self, generation: u64, hits: Vec<SearchHit>, cx: &mut Context<Self>) {
296 if generation != self.generation {
297 return;
298 }
299 self.local_messages = message_results(
300 hits,
301 &self.conversations,
302 Local::now().date_naive(),
303 app_base::format::Zone::Local,
304 );
305 self.messages = merge_messages(
306 &self.local_messages,
307 std::mem::take(&mut self.messages),
308 MAX_MESSAGE_RESULTS,
309 );
310 cx.notify();
311 }
312
289 313 fn schedule_server_search(&mut self, query: String, cx: &mut Context<Self>) {
290 314 let Some(engine) = self.app.read(cx).engine.clone() else {
291 315 return;
@@ -260,32 +260,56 @@ impl Switcher {
260 self.results = fuzzy::rank(query, &self.candidates, limit);
260 self.results = fuzzy::rank(query, &self.candidates, limit);
261 self.results
261 self.results
262 .sort_by_key(|candidate| candidate.group() != "Chats");
262 .sort_by_key(|candidate| candidate.group() != "Chats");
263 self.local_messages = if wants_messages {
263 self.local_messages.clear();
264 let hits = self
264 self.messages.clear();
265 .app
266 .read(cx)
267 .store
268 .search_messages(query, None, MAX_MESSAGE_RESULTS)
269 .unwrap_or_default();
270 let now = Local::now();
271 message_results(
272 hits,
273 &self.conversations,
274 now.date_naive(),
275 app_base::format::Zone::Local,
276 )
277 } else {
278 Vec::new()
279 };
280 self.messages = self.local_messages.clone();
281 self.people.clear();
265 self.people.clear();
282 self.highlighted = 0;
266 self.highlighted = 0;
283 self.generation += 1;
267 self.generation += 1;
268 if wants_messages {
269 self.schedule_local_search(query.to_owned(), cx);
270 }
284 if query.trim().chars().count() >= MIN_SERVER_QUERY_CHARS {
271 if query.trim().chars().count() >= MIN_SERVER_QUERY_CHARS {
285 self.schedule_server_search(query.trim().to_owned(), cx);
272 self.schedule_server_search(query.trim().to_owned(), cx);
286 }
273 }
287 }
274 }
288
275
276 fn schedule_local_search(&mut self, query: String, cx: &mut Context<Self>) {
277 let store = self.app.read(cx).store.clone();
278 let generation = self.generation;
279 cx.spawn(async move |this, cx| {
280 let hits = cx
281 .background_spawn(async move {
282 store
283 .search_messages(&query, None, MAX_MESSAGE_RESULTS)
284 .unwrap_or_default()
285 })
286 .await;
287 this.update(cx, |switcher, cx| {
288 switcher.apply_local(generation, hits, cx)
289 })
290 .ok();
291 })
292 .detach();
293 }
294
295 fn apply_local(&mut self, generation: u64, hits: Vec<SearchHit>, cx: &mut Context<Self>) {
296 if generation != self.generation {
297 return;
298 }
299 self.local_messages = message_results(
300 hits,
301 &self.conversations,
302 Local::now().date_naive(),
303 app_base::format::Zone::Local,
304 );
305 self.messages = merge_messages(
306 &self.local_messages,
307 std::mem::take(&mut self.messages),
308 MAX_MESSAGE_RESULTS,
309 );
310 cx.notify();
311 }
312
289 fn schedule_server_search(&mut self, query: String, cx: &mut Context<Self>) {
313 fn schedule_server_search(&mut self, query: String, cx: &mut Context<Self>) {
290 let Some(engine) = self.app.read(cx).engine.clone() else {
314 let Some(engine) = self.app.read(cx).engine.clone() else {
291 return;
315 return;
crates/store/src/search.rs +15 −4
@@ -108,8 +108,14 @@ impl Store {
108 108 FROM message_search
109 109 JOIN search_keys k ON k.id = message_search.rowid
110 110 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
111 WHERE message_search MATCH ?1 AND (?2 IS NULL OR k.conversation_id = ?2)
112 ORDER BY m.created_at DESC LIMIT ?3",
111 WHERE message_search MATCH ?1
112 AND message_search.rowid IN (
113 SELECT k.id FROM message_search
114 JOIN search_keys k ON k.id = message_search.rowid
115 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
116 WHERE message_search MATCH ?1 AND (?2 IS NULL OR k.conversation_id = ?2)
117 ORDER BY m.created_at DESC LIMIT ?3)
118 ORDER BY m.created_at DESC",
113 119 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
114 120 ))?;
115 121 let hits = statement
@@ -144,8 +150,13 @@ impl Store {
144 150 JOIN search_keys k ON k.id = message_search.rowid
145 151 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
146 152 WHERE message_search MATCH ?1
147 AND k.conversation_id IN (SELECT value FROM json_each(?2))
148 ORDER BY m.created_at DESC LIMIT ?3",
153 AND message_search.rowid IN (
154 SELECT k.id FROM message_search
155 JOIN search_keys k ON k.id = message_search.rowid
156 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
157 WHERE message_search MATCH ?1 AND k.conversation_id IN (SELECT value FROM json_each(?2))
158 ORDER BY m.created_at DESC LIMIT ?3)
159 ORDER BY m.created_at DESC",
149 160 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
150 161 ))?;
151 162 let hits = statement
@@ -108,8 +108,14 @@ impl Store {
108 FROM message_search
108 FROM message_search
109 JOIN search_keys k ON k.id = message_search.rowid
109 JOIN search_keys k ON k.id = message_search.rowid
110 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
110 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
111 WHERE message_search MATCH ?1 AND (?2 IS NULL OR k.conversation_id = ?2)
111 WHERE message_search MATCH ?1
112 ORDER BY m.created_at DESC LIMIT ?3",
112 AND message_search.rowid IN (
113 SELECT k.id FROM message_search
114 JOIN search_keys k ON k.id = message_search.rowid
115 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
116 WHERE message_search MATCH ?1 AND (?2 IS NULL OR k.conversation_id = ?2)
117 ORDER BY m.created_at DESC LIMIT ?3)
118 ORDER BY m.created_at DESC",
113 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
119 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
114 ))?;
120 ))?;
115 let hits = statement
121 let hits = statement
@@ -144,8 +150,13 @@ impl Store {
144 JOIN search_keys k ON k.id = message_search.rowid
150 JOIN search_keys k ON k.id = message_search.rowid
145 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
151 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
146 WHERE message_search MATCH ?1
152 WHERE message_search MATCH ?1
147 AND k.conversation_id IN (SELECT value FROM json_each(?2))
153 AND message_search.rowid IN (
148 ORDER BY m.created_at DESC LIMIT ?3",
154 SELECT k.id FROM message_search
155 JOIN search_keys k ON k.id = message_search.rowid
156 JOIN messages m ON m.conversation_id = k.conversation_id AND m.message_id = k.message_id
157 WHERE message_search MATCH ?1 AND k.conversation_id IN (SELECT value FROM json_each(?2))
158 ORDER BY m.created_at DESC LIMIT ?3)
159 ORDER BY m.created_at DESC",
149 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
160 HIGHLIGHT_START as u32, HIGHLIGHT_END as u32
150 ))?;
161 ))?;
151 let hits = statement
162 let hits = statement