Compare commits

..

No commits in common. "master" and "1.0.3" have entirely different histories.

3 changed files with 13 additions and 33 deletions

View file

@ -1,7 +1,7 @@
{
"id": "one-step-wiki-link",
"name": "One Step Wiki Link",
"version": "1.0.4",
"version": "1.0.2",
"minAppVersion": "1.8.0",
"description": "一步添加 wiki 链接",
"author": "Busyo",

View file

@ -1,6 +1,6 @@
{
"name": "one-step-wiki-link",
"version": "1.0.4",
"version": "1.0.2",
"description": "一步添加 wiki 链接",
"main": "main.js",
"scripts": {

View file

@ -1,7 +1,6 @@
import { Editor, EditorPosition, MarkdownView, normalizePath, Plugin, TFile } from "obsidian";
import { Editor, MarkdownView, normalizePath, Plugin, TFile } from "obsidian";
import { OneStepWikiLinkPluginSettingTab } from "./setting";
import { Localization } from "./localization";
import { start } from "repl";
interface OneStepWikiLinkPluginSettings {
@ -162,8 +161,7 @@ export default class OneStepWikiLinkPlugin extends Plugin {
this.registerEvent(this.app.vault.on("rename", (file, oldPath) => {
if (file && file instanceof TFile) {
let fileName = oldPath.substring(oldPath.lastIndexOf('/') + 1).replace(".md", "");
this.updateFileNameList(file.basename, true, fileName);
this.updateFileNameList(file.basename, true, oldPath.replace(".md", ""));
}
}));
@ -205,8 +203,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
this.fileNameList.push(file.basename);
}
this.fileNameList.sort((a, b) => a.length > b.length ? -1 : 1);
}
updateFileNameList(name: string, add: boolean, extra: string = "") {
@ -231,19 +227,18 @@ export default class OneStepWikiLinkPlugin extends Plugin {
this.divForDetails.empty();
}
let contentWithoutLinks = data.replace(/\[\[([^\[\]]+)\]\]/g, "");
const contentWithoutLinks = data.replace(/\[\[([^\[\]]+)\]\]/g, "");
this.fileNameList.forEach(fileName => {
let regex = new RegExp(`${fileName}\\b`, "g");
let regex = new RegExp(`(?<!\\[\\[)${fileName}\\b(?!\\]\\])`, "g");
//检测字符串最后一个字符是否为有边界的语言
if (this.isNonBoundaryChar(fileName.charAt(fileName.length - 1))) {
regex = new RegExp(`${fileName}`, "g");
regex = new RegExp(`(?<!\\[\\[)${fileName}(?!\\]\\])`, "g");
}
const newContent = contentWithoutLinks.replace(regex, "");
// 排除当前文件
if (fileName !== this.currentFileName && newContent !== contentWithoutLinks) {
if (fileName !== this.currentFileName && regex.exec(contentWithoutLinks) !== null) {
this.matchingFiles.push(fileName);
//添加详情
@ -253,8 +248,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
text: fileName
});
}
contentWithoutLinks = newContent;
}
});
@ -282,7 +275,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
if (this.openEditor) {
let data = this.openEditor.getValue();
let rawChanges: { start: number; end: number; change: { from: EditorPosition, to: EditorPosition, text: string } }[] = [];
let changes = [];
for (const match of this.matchingFiles) {
@ -298,25 +290,13 @@ export default class OneStepWikiLinkPlugin extends Plugin {
let pos = this.openEditor.offsetToPos(res.index);
let endPos = { ch: pos.ch + match.length, line: pos.line };
rawChanges.push({
start: res.index,
end: res.index + match.length,
change: {
from: pos,
to: endPos,
text: `[[${match}]]`
}
changes.push({
from: pos,
to: endPos,
text: `[[${match}]]`
});
}
}
rawChanges.sort((a, b) => a.start - b.start);
let endIndex = -1;
for (let raw of rawChanges) {
if (raw.start >= endIndex) {
changes.push(raw.change);
endIndex = raw.end;
// data = data.replace(regex, `[[${match}]]`);
}
}