1772367588

This commit is contained in:
Docker7530
2026-03-01 20:20:04 +08:00
parent c6125c117b
commit a2f5df43cc
24 changed files with 314 additions and 225 deletions
+4
View File
@@ -48,3 +48,7 @@
| 输入行为 | `/` 单独作为输入 | 斜杠被占用为引导键,配置里用双击 `/` 方式输入本身 | `wanxiang.schema.yaml` |
| 候选存在 | `[` / `]` | 以词定字:取首字/末字 | `wanxiang.schema.yaml` |
| 候选存在 | `,` | super_tips 上屏按键 | `wanxiang.schema.yaml` |
![](../../attachment/Pasted%20image%2020260228121011.png)
![](../../attachment/Pasted%20image%2020260228121021.png)
@@ -0,0 +1,21 @@
module.exports = async (params) => {
const { app } = params;
// 获取当前仓库路径
const vaultPath = app.vault.adapter.basePath;
// 构建 Windows Terminal 命令
const command = `wt -d "${vaultPath}"`;
// 使用 Node.js child_process 执行命令
const { exec } = require('child_process');
exec(command, (error, stdout, stderr) => {
if (error) {
console.error('执行失败:', error);
new Notice('无法打开终端');
return;
}
console.log('终端已打开');
});
};
@@ -0,0 +1,69 @@
module.exports = async (params) => {
const { app, obsidian, quickAddApi } = params;
// 获取当前选中的文件或让用户选择图片文件
const activeFile = app.workspace.getActiveFile();
if (
!activeFile ||
!activeFile.extension.match(/(png|jpg|jpeg|gif|webp|svg)/i)
) {
new obsidian.Notice("请先选择一个图片文件");
return;
}
// 生成UUID
const uuid = crypto.randomUUID();
const newFileName = `${uuid}.${activeFile.extension}`;
const newPath = activeFile.path.replace(activeFile.name, newFileName);
// 获取所有引用该文件的笔记
const backlinks = app.metadataCache.getBacklinksForFile(activeFile);
// 确认操作
const confirm = await quickAddApi.yesNoPrompt(
"确认重命名",
`${activeFile.name} 重命名为 ${newFileName}\n` +
`将更新 ${backlinks.data.size} 个文件中的引用`,
);
if (!confirm) return;
try {
// 重命名文件
await app.fileManager.renameFile(activeFile, newPath);
// 更新所有引用
let updatedCount = 0;
for (const [file, links] of backlinks.data) {
const fileObj = app.vault.getAbstractFileByPath(file);
if (fileObj instanceof obsidian.TFile) {
let content = await app.vault.read(fileObj);
// 更新所有链接引用
for (const link of links) {
const oldLink = `[[${activeFile.path}]]`;
const newLink = `[[${newPath}]]`;
const oldEmbed = `![[${activeFile.path}]]`;
const newEmbed = `![[${newPath}]]`;
content = content.replace(
new RegExp(oldLink.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
newLink,
);
content = content.replace(
new RegExp(oldEmbed.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
newEmbed,
);
}
await app.vault.modify(fileObj, content);
updatedCount++;
}
}
new obsidian.Notice(`成功重命名并更新了 ${updatedCount} 个文件`);
} catch (error) {
console.error("重命名失败:", error);
new obsidian.Notice("重命名失败: " + error.message);
}
};