抱怨思源笔记不能 shift+click 多选文档已久
终于忍无可忍,用了 3 分钟让 claude 写了一个代码片段
暂时用了没有问题,有问题欢迎反馈
使用方法
普通 click 点击第一个文档,按 shift+click 点击最后一个文档,即可选中区域内的所有文档进行批量操作(删除、移动等)
代码片段
(() => { let lastClickedItem = null; function handleFileClick(event) { if (!event.shiftKey) { // 普通点击,记录最后点击的项目 lastClickedItem = event.target.closest('li[data-type="navigation-file"]'); return; } const currentItem = event.target.closest('li[data-type="navigation-file"]'); if (!currentItem || !lastClickedItem) return; // 获取所有文档项 const allFiles = Array.from(document.querySelectorAll('li[data-type="navigation-file"]')); // 获取起始和结束索引 const startIndex = allFiles.indexOf(lastClickedItem); const endIndex = allFiles.indexOf(currentItem); if (startIndex === -1 || endIndex === -1) return; // 确定选择范围 const start = Math.min(startIndex, endIndex); const end = Math.max(startIndex, endIndex); // 清除现有选择 allFiles.forEach(file => { file.classList.remove('b3-list-item--focus'); }); // 添加新选择 for (let i = start; i <= end; i++) { allFiles[i].classList.add('b3-list-item--focus'); } // 阻止默认行为 event.preventDefault(); event.stopPropagation(); } function initShiftSelect() { // 移除可能存在的旧事件监听器 document.removeEventListener('click', handleFileClick, true); // 添加新的事件监听器 document.addEventListener('click', handleFileClick, true); } // 初始化 initShiftSelect(); // 导出初始化函数,以便需要时重新初始化 window.initShiftSelect = initShiftSelect; })();
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于