]> acesimba.cloud Git - codebuddy-web.git/commitdiff
fix(frontend): 编辑任务名称时暂停列表自动刷新,避免输入框被刷新清空
authorCodebuddy <codebuddy@localhost>
Mon, 7 Sep 2026 09:35:09 +0000 (17:35 +0800)
committerCodebuddy <codebuddy@localhost>
Mon, 7 Sep 2026 09:35:09 +0000 (17:35 +0800)
frontend/index.html

index 9f9b250487ce658f0180ca651df9b1e60f9690d7..46c2a3d8ed3a68f9192542237712d7646373fd89 100644 (file)
@@ -638,6 +638,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; heigh
   // 列表页自动刷新:进入时启动,离开/退出时停止
   let pickerTimer = null;
   let pickerRefreshing = false;
+  let editingTaskId = null;   // 正在内联编辑的任务 id;非 null 时暂停自动刷新重建,避免打断输入
   function startPickerRefresh() {
     stopPickerRefresh();
     pickerTimer = setInterval(refreshTasks, 5000);
@@ -647,6 +648,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; heigh
   }
   async function refreshTasks() {
     if (pickerRefreshing) return;
+    if (editingTaskId) return;  // 正在编辑任务名称/描述/分组,跳过本轮重建,避免输入框被刷新清空
     pickerRefreshing = true;
     try {
       await renderTasks();
@@ -887,6 +889,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; heigh
 
   // 进入卡片内联编辑模式:编辑名称、描述与所属分组
   function enterEditMode(card, t) {
+    editingTaskId = t.id;
     const curGroup = t.group || '';
     const groupOpts = '<option value="">未分类</option>' +
       groupsCache.map(g =>
@@ -911,7 +914,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; heigh
     descInput.addEventListener('input', updateCounter);
     nameInput.focus();
     nameInput.select();
-    card.querySelector('.tc-cancel').onclick = () => renderTasks();
+    card.querySelector('.tc-cancel').onclick = () => { editingTaskId = null; renderTasks(); };
     card.querySelector('.tc-save').onclick = async () => {
       const newName = nameInput.value.trim();
       const newDesc = descInput.value;
@@ -922,6 +925,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; heigh
         body: JSON.stringify({ name: newName, description: newDesc, group: newGroup }),
       });
       if (!res.ok) { const d = await res.json().catch(()=>({})); alert(d.error || '保存失败'); return; }
+      editingTaskId = null;
       await renderTasks();
     };
   }