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; } }