From 7540fc8bb13be0f3db561c93b77314b27ee6ffb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BD=E6=9C=BD=E6=9C=BD=E6=9C=BD=E6=9C=BD?= <694253220@qq.com> Date: Tue, 8 Apr 2025 21:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=95=BF=E7=9F=AD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E5=B5=8C=E5=A5=97=E5=8C=B9=E9=85=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A6=82=EF=BC=9A=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6=E5=90=8D=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20[=E6=96=87=E4=BB=B6=EF=BC=8C=E6=96=87=E4=BB=B6=E5=90=8D]=20?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E6=AD=A3=E6=96=87=E4=B8=BA=20=E8=BF=99?= =?UTF-8?q?=E6=98=AF=E6=96=87=E4=BB=B6=E5=90=8D=20=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E4=BC=9A=E9=83=BD=E5=8C=B9=E9=85=8D=E5=88=B0?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E6=9B=BF=E6=8D=A2=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E4=BC=9A=E6=9B=BF=E6=8D=A2=E6=88=90=20=E8=BF=99?= =?UTF-8?q?=E6=98=AF[[=E6=96=87=E4=BB=B6]][[=E6=96=87=E4=BB=B6=E5=90=8D]]?= =?UTF-8?q?=20=E8=BF=99=E6=A0=B7=E7=9A=84=E9=94=99=E8=AF=AF=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/manifest.json b/manifest.json index 8f03e59..a6ff3a7 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "one-step-wiki-link", "name": "One Step Wiki Link", - "version": "1.0.3", + "version": "1.0.4", "minAppVersion": "1.8.0", "description": "一步添加 wiki 链接", "author": "Busyo", diff --git a/package.json b/package.json index 727f8eb..bd94855 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "one-step-wiki-link", - "version": "1.0.3", + "version": "1.0.4", "description": "一步添加 wiki 链接", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 8f64dc3..4cf73ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ -import { Editor, MarkdownView, normalizePath, Plugin, TFile } from "obsidian"; +import { Editor, EditorPosition, MarkdownView, normalizePath, Plugin, TFile } from "obsidian"; import { OneStepWikiLinkPluginSettingTab } from "./setting"; import { Localization } from "./localization"; +import { start } from "repl"; interface OneStepWikiLinkPluginSettings { @@ -204,6 +205,8 @@ 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 = "") { @@ -228,18 +231,19 @@ export default class OneStepWikiLinkPlugin extends Plugin { this.divForDetails.empty(); } - const contentWithoutLinks = data.replace(/\[\[([^\[\]]+)\]\]/g, ""); + let contentWithoutLinks = data.replace(/\[\[([^\[\]]+)\]\]/g, ""); this.fileNameList.forEach(fileName => { - let regex = new RegExp(`(? a.start - b.start); + + let endIndex = -1; + for (let raw of rawChanges) { + if (raw.start >= endIndex) { + changes.push(raw.change); + endIndex = raw.end; } }