()
| 1972 | |
| 1973 | |
| 1974 | function deleteCurrentNote(){ |
| 1975 | if (!currentNoteId) { |
| 1976 | alert('请先选择一篇笔记'); |
| 1977 | return; |
| 1978 | } |
| 1979 | |
| 1980 | const map = readJSON(LS_KEYS.notes, {}); |
| 1981 | const list = map[currentCategoryId] || []; |
| 1982 | const noteIndex = list.findIndex(n => n.id === currentNoteId); |
| 1983 | |
| 1984 | if (noteIndex === -1) { |
| 1985 | alert('找不到要删除的笔记'); |
| 1986 | return; |
| 1987 | } |
| 1988 | |
| 1989 | const note = list[noteIndex]; |
| 1990 | const ok = confirm(`确定删除笔记"${note.title || '未命名'}"?\n\n删除的笔记将移入回收站,可在30天内恢复。`); |
| 1991 | if (!ok) return; |
| 1992 | |
| 1993 | // 将笔记移到回收站 |
| 1994 | const trashData = readJSON(LS_KEYS.trash, []); |
| 1995 | const trashNote = { |
| 1996 | ...note, |
| 1997 | deletedAt: Date.now(), |
| 1998 | originalCategoryId: currentCategoryId, |
| 1999 | originalCategoryName: readJSON(LS_KEYS.categories, []).find(c => c.id === currentCategoryId)?.name || '未知分类' |
| 2000 | }; |
| 2001 | trashData.unshift(trashNote); |
| 2002 | writeJSON(LS_KEYS.trash, trashData); |
| 2003 | |
| 2004 | // 从原列表中移除笔记 |
| 2005 | list.splice(noteIndex, 1); |
| 2006 | map[currentCategoryId] = list; |
| 2007 | writeJSON(LS_KEYS.notes, map); |
| 2008 | |
| 2009 | // 清空编辑器并重新渲染列表 |
| 2010 | currentNoteId = null; |
| 2011 | window.currentNoteId = currentNoteId; |
| 2012 | clearEditor(); |
| 2013 | renderNotes(); |
| 2014 | |
| 2015 | // 更新按钮文本 |
| 2016 | updateButtonTexts(); |
| 2017 | } |
| 2018 | |
| 2019 | // 显示历史记录弹窗 |
| 2020 | function showHistoryDialog() { |
nothing calls this directly
no test coverage detected