Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

feat(web): 全站共用一个 Search Input,筛选等中文输入法组完字

longmeidao4dd7eee90ef4
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 80c972202..91432a89b 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -1450,7 +1450,10 @@ class FollowWebSourceTests(unittest.TestCase):
page = self.page
form = page[page.index('<form class="faddform" id="followAdd">'):]
form = form[:form.index("</form>")]
- self.assertIn('<input type="search" name="line" required', form)
+ # 输入框本体是共用的 Search Input(见 web/js/ui-components.js),
+ # 关注页这里只交名字、无障碍名称和 required。
+ self.assertIn("searchInputHtml({name:'line',label:'来源链接、名字或 id',", form)
+ self.assertIn("attrs:'required'", form)
self.assertNotIn("textarea", form)
self.assertNotIn('type="submit"', form)
# 忙态没有按钮可以变灰,就落在表单自己身上:前缀图标原位换 Spinner。
@@ -1589,10 +1592,13 @@ class FollowWebSourceTests(unittest.TestCase):
def test_the_input_and_its_button_are_the_same_height(self):
# 输入框和旁边的来源筛选按钮齐平;单行以后没有 min-height 与 resize。
+ # 几何住在共用的 .geist-search 里,关注页不再复制一份自己的输入框样式。
page = self.page
- self.assertEqual(page.count('.faddform input[type="search"]{'), 1,
+ self.assertEqual(page.count('.geist-search input[type="search"]{'), 1,
"旧规则留在后面会覆盖新输入框样式")
- rule = page[page.index('.faddform input[type="search"]{'):]
+ self.assertEqual(page.count('.faddform input[type="search"]{'), 0,
+ "关注页私有的输入框几何已经上提到 .geist-search")
+ rule = page[page.index('.geist-search input[type="search"]{'):]
rule = rule[:rule.index("}")]
self.assertIn("height:38px", rule)
self.assertIn("padding:0 12px 0 38px", rule)
@@ -1737,10 +1743,13 @@ class FollowWebSourceTests(unittest.TestCase):
body = page[page.index("function renderFollowManage("):
page.index("function wireFollowItems(")]
form = body[body.index('<form class="faddform"'):body.index("</form>")]
- hint = form[form.index("placeholder="):form.index("aria-label=")]
- self.assertIn("粘贴来源链接,或输入作者名、id…", hint)
+ hint = form[form.index("placeholder:'") + len("placeholder:'"):]
+ hint = hint[:hint.index("'")]
+ self.assertEqual(hint, "粘贴来源链接,或输入作者名、id…")
self.assertNotIn("${", hint, "占位文字不许由数据拼出来——那就是把推荐塞进去了")
- self.assertEqual(body.count("placeholder="), 1)
+ # 这一段里只有一处写死的占位文字。骨架那处 `placeholder:managementPlaceholder(…)`
+ # 是路由占位结构,不是输入框里的字,用带引号的形式把两者分开数。
+ self.assertEqual(body.count("placeholder:'"), 1)
def test_every_credential_state_sits_in_the_same_column(self):
"""summary 是 .frow 的 flex 子项,默认不撑满整行——于是有折叠体的那几行
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 31d4b8227..4d71ca142 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -674,6 +674,75 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains('@media (max-width:760px){input,textarea,select{font-size:16px!important}}')
self.assertPageContains('button,a,input,textarea,select,summary{touch-action:manipulation}')
+ def test_search_inputs_share_one_component_with_a_visible_focus_ring(self):
+ """带搜索语义的输入只有一份实现,点进去看得见焦点。
+
+ Geist Search Input 的契约是:搜索图标占前缀位,查找中原位换 Spinner,
+ 输入框几何不变。关注页先有了这套,索引页的筛选框却是另一份私有样式——
+ 没有前缀图标、没有任何 focus 规则,点进去和没点一个样。
+ """
+ self.assertPageContains("export function searchInputHtml({label,id='',name='',value='',placeholder='',attrs=''}={})")
+ self.assertCode("""const parts=[
+ 'type="search"',""")
+ self.assertPageContains('<input ${parts}></div>')
+ self.assertPageContains('<div class="geist-search" data-search-input>')
+ self.assertPageContains(
+ """<span class="geist-search-prefix" data-search-prefix>${icon('search')}</span>""")
+ # 焦点环与顶部搜索框同一个配方,不是第二种蓝。
+ self.assertCode('.geist-search input[type="search"]:focus{outline:0;'
+ 'border-color:color-mix(in srgb,var(--tungsten) 72%,transparent);'
+ 'box-shadow:0 0 0 3px color-mix(in srgb,var(--tungsten) 26%,transparent)}')
+ # 忙态换的是前缀位,输入框自己不动;hook 跟着组件走,不留关注页专属的名字。
+ self.assertPageContains("form.querySelector('[data-search-prefix]')")
+ self.assertPageContains("if(prefix)prefix.innerHTML=spinnerHtml('查找中');")
+ self.assertPageLacks("data-follow-search-prefix")
+ self.assertPageLacks("fsearchprefix")
+ # 两个调用点都走组件;索引页的筛选框不再用 placeholder 当标签。
+ self.assertPageContains("searchInputHtml({id:'iq',label:'过滤'+title,value:q||''})")
+ self.assertPageContains("searchInputHtml({name:'line',label:'来源链接、名字或 id',")
+ self.assertPageLacks('<input id="iq" placeholder="过滤…"')
+ self.assertPageLacks(".isearch")
+
+ def test_filtering_waits_for_the_chinese_ime_to_finish_composing(self):
+ """选字过程中不查询:拿半截拼音去筛选,筛的是「zhon」这种不存在的词。
+
+ `input` 在组字过程中照样发,事件上的 `isComposing` 是唯一可靠的判据;
+ 组完由 `compositionend` 接手。回车同理——那一下是定字,不是提交。
+ """
+ self.assertPageContains("iq.oninput=e=>{if(e.isComposing)return;refineIndex()};")
+ self.assertPageContains("iq.oncompositionend=refineIndex;")
+ self.assertPageContains("$('#q').oninput=e=>{if(e.isComposing)return;refreshSearchMenu()};")
+ self.assertPageContains("$('#q').oncompositionend=refreshSearchMenu;")
+ self.assertPageContains("search.oninput=e=>{if(e.isComposing)return;renderPicker()};")
+ self.assertPageContains("search.oncompositionend=renderPicker;")
+ # 顶部搜索和标签选择器的键盘处理在最前面让位给输入法。
+ self.assertPageLacks("$('#q').oninput=()=>{searchActive=-1;")
+ self.assertPageLacks("search.oninput=renderPicker;")
+ self.assertEqual(self.app_js.count("if(e.isComposing)return;"), 5,
+ "五处:索引筛选、顶部搜索的输入与键盘、标签选择器的输入与键盘")
+ # 只读筛选没有提交按钮,回车必须自己接管:不接就是按了没反应。
+ self.assertPageContains("iq.onkeydown=e=>{if(e.isComposing||e.key!=='Enter')return;")
+ self.assertPageContains(
+ "e.preventDefault();clearTimeout(it2);openIndex(kind,iq.value.trim(),true,true)};")
+
+ def test_a_filter_rerun_keeps_the_input_alive_instead_of_repainting_the_page(self):
+ """重画整屏会把正在打字的那个输入框换掉,光标和未定型的拼音一起丢。
+
+ 筛选框重跑不是一次页面进入:既不该铺骨架(同步就能给的控件不进骨架),
+ 也不该重画表头。表头里随查询变的只有计数,单独改它。
+ """
+ self.assertPageContains("async function openIndex(kind,q,push=true,refine=false)")
+ self.assertPageContains("if(!refine)showIndexLoading(people?'正在读取作者':'正在读取标签')")
+ self.assertCode("""if(refine&&$('#iq')){
+ $('#indexCount').textContent=countText;
+ $('#indexFilters').innerHTML=filters;
+ $('#indexBody').innerHTML=body;
+ $('#indexMore').hidden=!d.has_more;
+ }else""")
+ # 分类筛选自己有容器,才能不动表头单独换掉。
+ self.assertPageContains('<div id="indexFilters">${filters}</div>')
+ self.assertPageContains("it2=setTimeout(()=>openIndex(kind,iq.value.trim(),true,true),300)")
+
def test_route_titles_and_settings_dialog_manage_focus(self):
# 标题跟着路由表走:每一屏的标签写在自己那条记录上,不再有第二份
# 「路径 → 标题」映射跟路由分支各自演化。
@@ -1335,7 +1404,7 @@ class WebUiSourceTests(unittest.TestCase):
def test_search_active_index_resets_when_the_list_is_rebuilt(self):
# 列表重建后旧索引会指向不存在的行;输入和重新渲染都必须归零。
self.assertPageContains("menu.hidden=false;searchActive=-1;")
- self.assertPageContains("$('#q').oninput=()=>{searchActive=-1;")
+ self.assertPageContains("const refreshSearchMenu=()=>{searchActive=-1;")
def test_enter_uses_the_highlighted_option_before_the_suggestion(self):
self.assertPageContains("const picked=searchOptions()[searchActive]")
@@ -3367,7 +3436,7 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("placeholder:followSkeletonHtml('正在读取关注内容')")
self.assertPageContains("pageSkeletonHtml('正在读取统计',{variant:'dashboard'})")
self.assertPageContains(".skeletondashhero{min-height:330px;grid-template-columns:minmax(260px,36%) minmax(0,1fr)}")
- self.assertPageContains("showIndexLoading(people?'正在读取作者':'正在读取标签')")
+ self.assertPageContains("if(!refine)showIndexLoading(people?'正在读取作者':'正在读取标签')")
self.assertPageContains("$('#loadSentinel').innerHTML=loadingDotsHtml('继续载入中…')")
self.assertPageContains("pageSkeletonHtml('正在读取推荐',{cards:true,className:'related-skeleton'})")
self.assertPageLacks("count.innerHTML=`${spinnerHtml(label)}<span>载入中…</span>`")
diff --git a/web/app.css b/web/app.css
index 1afc38dbf..9f1a302b0 100644
--- a/web/app.css
+++ b/web/app.css
@@ -96,6 +96,23 @@ button,a,input,textarea,select,summary{touch-action:manipulation}
.geist-loading-dots>i{width:4px;height:4px;border-radius:50%;background:currentColor;
animation:geist-loading-dot 1.2s ease-in-out infinite}
.geist-loading-dots>i:nth-child(2){animation-delay:.15s}.geist-loading-dots>i:nth-child(3){animation-delay:.3s}
+/* Geist Search Input:搜索图标占前缀位,查找中原位换 Spinner,输入框几何不变。
+ 全站带搜索语义的输入共用这一份,各处只加宽度和位置。 */
+.geist-search{position:relative;min-width:0}
+.geist-search-prefix{position:absolute;z-index:1;left:12px;top:11px;
+ display:grid;place-items:center;width:16px;height:16px;color:var(--muted);pointer-events:none}
+.geist-search-prefix>svg{width:16px;height:16px;stroke:currentColor;fill:none}
+.geist-search input[type="search"]{width:100%;min-width:0;height:38px;
+ box-sizing:border-box;border:1px solid var(--border-15);border-radius:var(--control-radius);
+ background:var(--ground);color:var(--ink);padding:0 12px 0 38px;font-size:var(--fs-md);font-family:inherit;
+ line-height:20px;transition:border-color .12s ease}
+.geist-search input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none;appearance:none}
+.geist-search input[type="search"]::placeholder{color:var(--muted)}
+/* 点进去要立刻看得出焦点在这儿,配方与顶部搜索框的 `.search:focus-within` 同一条。 */
+.geist-search input[type="search"]:focus{outline:0;
+ border-color:color-mix(in srgb,var(--tungsten) 72%,transparent);
+ box-shadow:0 0 0 3px color-mix(in srgb,var(--tungsten) 26%,transparent)}
+.geist-search:focus-within .geist-search-prefix{color:var(--ink)}
.geist-button{box-sizing:border-box;height:32px;padding:0 6px;border:1px solid var(--border-15);
border-radius:var(--control-radius);background:transparent;color:var(--ink);display:inline-flex;
align-items:center;justify-content:center;gap:6px;font:inherit;font-size:var(--fs-md);font-weight:500;
@@ -361,11 +378,8 @@ body.entity-open .index{overflow-x:visible}
.index .ihead{display:flex;align-items:center;gap:12px;margin-bottom:14px}
.index .ihead h2{margin:0}
.indexheading{display:inline-flex;align-items:center;gap:9px}.indexheading svg{width:25px;height:25px;stroke:currentColor;fill:none;stroke-width:1.8}
-.index .ihead .isearch{margin-left:auto}
+.index .ihead .geist-search{flex:1;max-width:320px;margin-left:auto}
#indexCount{color:var(--muted)}
-.index .isearch{flex:1;max-width:320px;background:var(--sunk);border:1px solid var(--line);
- border-radius:var(--pill-radius);padding:6px 14px}
-.index .isearch input{background:none;border:0;outline:none;width:100%}
.igrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:16px 10px}
.icell{display:flex;flex-direction:column;align-items:center;gap:6px;cursor:pointer;
background:none;border:0;color:inherit;padding:8px 4px;border-radius:var(--surface-radius)}
@@ -2409,18 +2423,8 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位
.fbtn svg{width:14px;height:14px;stroke:currentColor;fill:none;stroke-width:1.8}
.faddform{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;align-items:start}
-.fsearchinput{position:relative;min-width:0}.fsearchprefix{position:absolute;z-index:1;left:12px;top:11px;
- display:grid;place-items:center;width:16px;height:16px;color:var(--muted);pointer-events:none}
-.fsearchprefix>svg{width:16px;height:16px;stroke:currentColor;fill:none}
-.faddform input[type="search"]{width:100%;min-width:0;height:38px;
- box-sizing:border-box;border:1px solid var(--border-15);border-radius:var(--control-radius);
- background:var(--ground);color:var(--ink);padding:0 12px 0 38px;font-size:var(--fs-md);font-family:inherit;
- line-height:20px;transition:border-color .12s ease}
-.faddform input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none;appearance:none}
+/* 输入框本体是共用的 `.geist-search`;这里只管它和旁边按钮的高度对齐。 */
.faddform .fbtn{height:38px;min-height:38px}
-.faddform input[type="search"]::placeholder{color:var(--muted)}
-.faddform input[type="search"]:focus-visible{outline:2px solid var(--tungsten);outline-offset:1px;
- border-color:var(--tungsten)}
/* 没有按钮可以变灰,查找中的唯一凭据就是前缀位上的 Spinner——输入框自己必须还能改。 */
.faddform[aria-busy="true"] input[type="search"]{color:var(--muted)}
@@ -2581,7 +2585,7 @@ details.fcred{display:block}
.faliasmanager{margin-left:-13px;margin-right:-13px;margin-bottom:-14px}
.faliasmanager>summary{padding:2px 13px}
.faliasmanager .fcollapsebody{padding:4px 13px 14px}
- .faddform>.fsearchinput{grid-column:1/-1}
+ .faddform>.geist-search{grid-column:1/-1}
.faddform>.fsrcfilter{justify-self:start}
.frow{gap:8px}
.fsources,.fsources[data-layout="compact"]{grid-template-columns:1fr}
diff --git a/web/app.js b/web/app.js
index bf5ebb747..0ac93fc21 100644
--- a/web/app.js
+++ b/web/app.js
@@ -6,8 +6,8 @@ import { initMiddleTruncate } from './js/middle-truncate.js';
import { tagLabel } from './js/tags.js';
import {
breadcrumbHtml, checkboxHtml, emptyStateHtml, fieldsetTitle, iconSwitchHtml, loadingDotsHtml,
- mediaViewButtonsHtml, noteHtml, progressHtml, scrollerHtml, setActionBusy, skeletonHtml,
- spinnerHtml, wireBusyActions, wireCollapse, wireIconSwitch, wireScrollers,
+ mediaViewButtonsHtml, noteHtml, progressHtml, scrollerHtml, searchInputHtml, setActionBusy,
+ skeletonHtml, spinnerHtml, wireBusyActions, wireCollapse, wireIconSwitch, wireScrollers,
} from './js/ui-components.js';
initMiddleTruncate(document);
@@ -4334,11 +4334,8 @@ function renderFollowManage(credentials){
<section class="fsec">
<div class="fsechead"><h3>添加关注</h3></div>
<form class="faddform" id="followAdd">
- <div class="fsearchinput" data-follow-search-input>
- <span class="fsearchprefix" data-follow-search-prefix>${icon('search')}</span>
- <input type="search" name="line" required spellcheck="false" autocomplete="off"
- placeholder="粘贴来源链接,或输入作者名、id…"
- aria-label="来源链接、名字或 id"></div>
+ ${searchInputHtml({name:'line',label:'来源链接、名字或 id',
+ placeholder:'粘贴来源链接,或输入作者名、id…',attrs:'required'})}
<div class="fsrcfilter" id="followSrcFilter"></div>
</form>
<p class="fnote" data-follow-add-state aria-live="polite"></p>
@@ -4498,7 +4495,7 @@ function wireFollowManage(){
/* 状态提示在表单外面的说明行里,不能在 form 里找——找不到就是 null,
第一次赋值直接抛 TypeError,整个提交静默失败。 */
const state=root.querySelector('[data-follow-add-state]');
- const prefix=form.querySelector('[data-follow-search-prefix]');
+ const prefix=form.querySelector('[data-search-prefix]');
const line=String(new FormData(form).get('line')||'').trim();
if(!line)return;
const lines=[line];
@@ -4863,7 +4860,8 @@ function paintTagIndexSelection(){
const count=panel.querySelector('[data-tag-selected]');if(count)count.textContent=`已选 ${selectedIndexTags.size} 个标签`;
const apply=panel.querySelector('[data-tag-apply]');if(apply)apply.disabled=!selectedIndexTags.size;
}
-async function openIndex(kind,q,push=true){
+/* refine=true 表示这一次是筛选框自己重跑,不是一次页面进入:既不铺骨架,也不重画表头。 */
+async function openIndex(kind,q,push=true,refine=false){
releaseHoverPreviews();
const requestSeq=++indexRequestSeq;
document.body.classList.remove('entity-open');
@@ -4883,7 +4881,9 @@ async function openIndex(kind,q,push=true){
// 写在前面等于自己加完自己删。
document.body.classList.add('index-open');
disposeStage(false);
- showIndexLoading(people?'正在读取作者':'正在读取标签');
+ /* 骨架只盖真正在等的内容区。筛选重跑时页面已经在这儿了,把骨架铺上去会连筛选框
+ 一起吃掉——同步就能给出的控件不进骨架,正在打字的那个更不能。 */
+ if(!refine)showIndexLoading(people?'正在读取作者':'正在读取标签');
/* 在线标签走关注页那套统计,形状与 /api/index 一致,所以分页、搜索和「载入更多」
这三处现成的机制换个地址就能用。 */
const indexApi=offset=>onlineTags
@@ -4928,14 +4928,32 @@ async function openIndex(kind,q,push=true){
<button type="button" data-tag-clear>清空</button>
<button type="button" class="primary" data-tag-apply disabled>显示结果</button>
</div>`:'');
- $('#index').innerHTML=`<div class="ihead">
+ const countText=`${tagItems.length}${d.has_more?'+':''} 项`;
+ /* 筛选重跑不重画表头:输入框是同一个节点,焦点、光标位置和中文输入法正在组的字
+ 才不会在 300 ms 后被换掉。表头里随查询变的只有计数一处,单独改它。 */
+ if(refine&&$('#iq')){
+ $('#indexCount').textContent=countText;
+ $('#indexFilters').innerHTML=filters;
+ $('#indexBody').innerHTML=body;
+ $('#indexMore').hidden=!d.has_more;
+ }else $('#index').innerHTML=`<div class="ihead">
<h2 class="disp indexheading">${kind==='tags'?icon('tags'):''}${title}</h2>
- <span class="mono" id="indexCount">${tagItems.length}${d.has_more?'+':''} 项</span>
+ <span class="mono" id="indexCount">${countText}</span>
${kind==='tags'?`<div class="tagmodes"><button data-tag-scope="local" aria-pressed="${!onlineTags}">${icon('database')}本地</button><button data-tag-scope="online" aria-pressed="${onlineTags}">${icon('globe')}在线</button></div>
<div class="tagmodes"><button data-tag-view="cloud" aria-pressed="${tagIndexMode==='cloud'}">${icon('tags')}标签云</button><button data-tag-view="alphabet" aria-pressed="${tagIndexMode==='alphabet'}">${icon('list-filter')}字母表</button></div>`:''}
- <div class="isearch"><input id="iq" placeholder="过滤…" value="${esc(q||'')}"></div>
- </div>${filters}<div id="indexBody">${body}</div><button class="indexmore" id="indexMore" type="button" ${d.has_more?'':'hidden'}>载入更多</button>`;
- let it2; $('#iq').oninput=e=>{clearTimeout(it2);it2=setTimeout(()=>openIndex(kind,e.target.value.trim(),true),300)};
+ ${searchInputHtml({id:'iq',label:'过滤'+title,value:q||''})}
+ </div><div id="indexFilters">${filters}</div><div id="indexBody">${body}</div><button class="indexmore" id="indexMore" type="button" ${d.has_more?'':'hidden'}>载入更多</button>`;
+ const iq=$('#iq');let it2;
+ const refineIndex=()=>{clearTimeout(it2);
+ it2=setTimeout(()=>openIndex(kind,iq.value.trim(),true,true),300)};
+ /* 中文输入法在选字过程中一样发 input,事件上的 isComposing 是唯一可靠的判据:
+ 拿还没定型的拼音去筛选,筛的是「zhon」这种半截输入。组完字由 compositionend 接手。 */
+ iq.oninput=e=>{if(e.isComposing)return;refineIndex()};
+ iq.oncompositionend=refineIndex;
+ /* 只读筛选不配提交按钮,回车就是「别等那 300 ms,现在就查」。组字过程中的回车
+ 是在定字,放过去会拿半截拼音发请求。 */
+ iq.onkeydown=e=>{if(e.isComposing||e.key!=='Enter')return;
+ e.preventDefault();clearTimeout(it2);openIndex(kind,iq.value.trim(),true,true)};
$('#index').querySelectorAll('[data-tag-scope]').forEach(b=>b.onclick=()=>{
if(tagIndexScope===b.dataset.tagScope)return;
tagIndexScope=b.dataset.tagScope;
@@ -6103,8 +6121,12 @@ function moveSearchActive(step){
options[searchActive].scrollIntoView({block:'nearest'});
return true;
}
-$('#q').oninput=()=>{searchActive=-1;if(!$('#searchMenu').hidden)renderSearchMenu()};
+const refreshSearchMenu=()=>{searchActive=-1;if(!$('#searchMenu').hidden)renderSearchMenu()};
+$('#q').oninput=e=>{if(e.isComposing)return;refreshSearchMenu()};
+$('#q').oncompositionend=refreshSearchMenu;
$('#q').onkeydown=e=>{
+ /* 组字过程中的方向键在挑候选字、回车在定字,都不是给这个菜单的。 */
+ if(e.isComposing)return;
if(e.key==='ArrowDown'||e.key==='ArrowUp'){
if(moveSearchActive(e.key==='ArrowDown'?1:-1))e.preventDefault();
return;
@@ -6509,8 +6531,11 @@ async function openItem(id,push=true,queueContext=null,anchor=null){
${q&&!exact?`<button class="tagpickitem" data-pick="${esc(search.value.trim())}">${icon('plus')}<span class="pickname">新建“${esc(search.value.trim())}”</span></button>`:''}</div></section>`;
activeIndex=-1;body.querySelectorAll('[data-pick]').forEach(b=>b.onclick=()=>{
const selected=b.getAttribute('aria-pressed')==='true',tag=b.dataset.pick;closePicker();if(!selected)addTag(tag)})};
- search.oninput=renderPicker;
+ search.oninput=e=>{if(e.isComposing)return;renderPicker()};
+ search.oncompositionend=renderPicker;
search.onkeydown=e=>{const options=[...body.querySelectorAll('[data-pick]')];
+ /* 选字那一下的回车是定字,不是「新建这个标签」——半截拼音会真的建成标签。 */
+ if(e.isComposing)return;
if(e.key==='Escape'){e.preventDefault();closePicker();plus.focus();return}
if(e.key==='ArrowDown'||e.key==='ArrowUp'){e.preventDefault();if(!options.length)return;
activeIndex=(activeIndex+(e.key==='ArrowDown'?1:-1)+options.length)%options.length;
diff --git a/web/js/ui-components.js b/web/js/ui-components.js
index bd137b675..557112db3 100644
--- a/web/js/ui-components.js
+++ b/web/js/ui-components.js
@@ -56,6 +56,28 @@ export function spinnerHtml(label='加载中'){
return `<span class="geist-spinner" role="status" aria-label="${esc(label)}">${bars}</span>`;
}
+/**
+ * Geist Search Input: search icon as a prefix, swapped in place for a Spinner
+ * while the query runs, and the input geometry never changes. Read-only queries
+ * carry no submit button, so the accessible name lives in `aria-label` — a
+ * placeholder is not a label, it disappears the moment there is text to read.
+ */
+export function searchInputHtml({label,id='',name='',value='',placeholder='',attrs=''}={}){
+ const parts=[
+ 'type="search"',
+ id?`id="${esc(id)}"`:'',
+ name?`name="${esc(name)}"`:'',
+ placeholder?`placeholder="${esc(placeholder)}"`:'',
+ `value="${esc(value)}"`,
+ `aria-label="${esc(label)}"`,
+ 'spellcheck="false" autocomplete="off"',
+ attrs,
+ ].filter(Boolean).join(' ');
+ return `<div class="geist-search" data-search-input>
+ <span class="geist-search-prefix" data-search-prefix>${icon('search')}</span>
+ <input ${parts}></div>`;
+}
+
/**
* Geist loading action: visually unavailable and inert without using native
* `disabled`, so the trigger keeps keyboard focus while its request is running.