Compare commits

..

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

3 changed files with 13 additions and 47 deletions

View file

@ -1,7 +1,7 @@
{
"id": "one-step-wiki-link",
"name": "One Step Wiki Link",
"version": "1.0.4",
"version": "1.0.1",
"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.1",
"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 {
@ -103,8 +102,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
this.openEditor = leaf.view.app.workspace.activeEditor?.editor;
// console.log(this.openEditor);
if (this.openEditor) {
this.currentFileName = ((leaf.view as MarkdownView).file as TFile).basename;
// console.log((leaf.view as MarkdownView).file?.basename);
this.checkContent(this.openEditor.getValue());
}
} else if (type == "empty") {
@ -138,18 +135,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
}
});
this.addCommand({
id: "convert-all-matching-words-to-wiki-links-zh",
name: "转换所有匹配的文本为维基链接",
// hotkeys: [{
// modifiers: ['Mod'],
// key: 'r'
// }],
editorCallback: (editor) => {
this.convert2WikiLink();
}
});
//监听文本变化
this.registerEvent(this.app.workspace.on("editor-change", async (file, data) => {
@ -162,8 +147,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 +189,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 +213,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 +234,6 @@ export default class OneStepWikiLinkPlugin extends Plugin {
text: fileName
});
}
contentWithoutLinks = newContent;
}
});
@ -282,7 +261,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 +276,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}]]`);
}
}