diff --git a/static/js/emailLibrary.js b/static/js/emailLibrary.js index bf8ca0e02..887459252 100644 --- a/static/js/emailLibrary.js +++ b/static/js/emailLibrary.js @@ -1768,7 +1768,7 @@ function _scoreFilterOption(opt, needle) { return 0; } -function _filterSuggestions(needle, limit = 8) { +function _filterSuggestions(needle, limit = 10) { const n = String(needle || '').trim().toLowerCase(); if (!n) return []; // Filter / attachment matches first — typing 'unread' should surface @@ -1781,7 +1781,21 @@ function _filterSuggestions(needle, limit = 8) { const contactMatches = src .map(s => ({ s: { kind: 'contact', ...s }, score: _scoreSuggestion(s, n) })) .filter(x => x.score > 0); - return filterMatches.concat(contactMatches) + // Email subject / sender-name matches — use the snapshot (unfiltered + // list) when available so suggestions don't shrink as pills narrow the + // visible grid. Cap to 4 so contacts + filters stay visible. + const emails = _libPreSearchEmails || state._libEmails || []; + const emailMatches = []; + for (const em of emails) { + const subj = String(em.subject || '').toLowerCase(); + const fromN = String(em.from_name || '').toLowerCase(); + let score = 0; + if (subj.startsWith(n) || fromN.startsWith(n)) score = 3; + else if (subj.includes(n) || fromN.includes(n)) score = 1; + if (score > 0) emailMatches.push({ s: { kind: 'email', uid: em.uid, subject: em.subject || '(no subject)', from_name: em.from_name || em.from_address || '' }, score }); + if (emailMatches.length >= 4) break; + } + return filterMatches.concat(contactMatches).concat(emailMatches) .sort((a, b) => b.score - a.score) .slice(0, limit) .map(x => x.s); @@ -2734,7 +2748,7 @@ function _createCard(em) { const star = document.createElement('span'); star.title = 'Favorited'; star.style.cssText = 'color:var(--accent, var(--red));opacity:0.85;flex-shrink:0;display:inline-flex;'; - star.innerHTML = ''; + star.innerHTML = ''; titleRow.appendChild(star); } @@ -3018,17 +3032,14 @@ async function _toggleCardPreview(card, em) { reader.innerHTML = `