mirror of
https://github.com/busyogg/OneStepWikiLink.git
synced 2026-07-22 05:41:52 +00:00
优化自动转换功能
This commit is contained in:
parent
f382c0b82c
commit
8ee3fc151b
3 changed files with 70 additions and 25 deletions
50
src/main.ts
50
src/main.ts
|
|
@ -11,6 +11,7 @@ export enum Language {
|
|||
interface OneStepWikiLinkPluginSettings {
|
||||
showDetails: boolean;
|
||||
autoConvert: boolean;
|
||||
autoConvertDelay: number;
|
||||
language: Language;
|
||||
NonBoundaryCheckers: string[];
|
||||
excludes: string[];
|
||||
|
|
@ -19,6 +20,7 @@ interface OneStepWikiLinkPluginSettings {
|
|||
const DEFAULT_SETTINGS: OneStepWikiLinkPluginSettings = {
|
||||
showDetails: true,
|
||||
autoConvert: false,
|
||||
autoConvertDelay: 500,
|
||||
language: Language.CN,
|
||||
NonBoundaryCheckers: ["Han", "Hiragana", "Katakana", "Hangul"],
|
||||
excludes: []
|
||||
|
|
@ -49,6 +51,8 @@ export default class OneStepWikiLinkPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
autoTimer: NodeJS.Timeout | undefined;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
|
|
@ -152,21 +156,12 @@ export default class OneStepWikiLinkPlugin extends Plugin {
|
|||
this.updateFileNameList((file as TFile).basename, false);
|
||||
}));
|
||||
|
||||
// this.registerEvent(this.app.workspace.on("file-open", async (file) => {
|
||||
// // console.log("file open", file);
|
||||
// this.openEditor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor;
|
||||
|
||||
// if (file) {
|
||||
// this.currentFileName = (file as TFile).basename;
|
||||
|
||||
// let content = await this.app.vault.read(file);
|
||||
// this.checkContent(content);
|
||||
// }
|
||||
// }));
|
||||
|
||||
// console.log(this.fileNameList)
|
||||
|
||||
// this.checkContent();
|
||||
this.registerDomEvent(document.body, "input", () => {
|
||||
clearTimeout(this.autoTimer);
|
||||
this.autoTimer = setTimeout(() => {
|
||||
this.autoConvert2WikiLink();
|
||||
}, this.settings.autoConvertDelay);
|
||||
});
|
||||
}
|
||||
|
||||
getAllFileNames() {
|
||||
|
|
@ -242,20 +237,20 @@ export default class OneStepWikiLinkPlugin extends Plugin {
|
|||
this.matchingFiles.sort((a, b) => a.length > b.length ? -1 : 1);
|
||||
|
||||
if (this.matchingFiles.length > 0) {
|
||||
|
||||
if (this.settings.autoConvert) {
|
||||
this.btnOneStep?.addClass("hide");
|
||||
this.divForDetails?.addClass("hide");
|
||||
this.convert2WikiLink();
|
||||
} else {
|
||||
this.btnOneStep?.removeClass("hide");
|
||||
this.settings.showDetails && this.divForDetails?.removeClass("hide");
|
||||
}
|
||||
this.btnOneStep?.removeClass("hide");
|
||||
this.settings.showDetails && this.divForDetails?.removeClass("hide");
|
||||
} else {
|
||||
this.btnOneStep?.addClass("hide");
|
||||
this.divForDetails?.addClass("hide");
|
||||
}
|
||||
}
|
||||
|
||||
autoConvert2WikiLink() {
|
||||
if (this.settings.autoConvert) {
|
||||
this.btnOneStep?.addClass("hide");
|
||||
this.divForDetails?.addClass("hide");
|
||||
this.convert2WikiLink();
|
||||
}
|
||||
}
|
||||
|
||||
/** 转换所有匹配项为维基链接 */
|
||||
|
|
@ -337,7 +332,12 @@ export default class OneStepWikiLinkPlugin extends Plugin {
|
|||
|
||||
//保存配置的时候检测是否需要显示目标 Div
|
||||
if (this.matchingFiles.length > 0) {
|
||||
!this.settings.showDetails && this.divForDetails?.removeClass("hide");
|
||||
// !this.settings.showDetails && this.divForDetails?.removeClass("hide");
|
||||
if (this.settings.showDetails) {
|
||||
this.divForDetails?.removeClass("hide");
|
||||
} else {
|
||||
this.divForDetails?.addClass("hide");
|
||||
}
|
||||
} else {
|
||||
this.divForDetails?.addClass("hide");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ export class OneStepWikiLinkPluginSettingTab extends PluginSettingTab {
|
|||
[Language.EN]: "Whether to automatically convert all matching content"
|
||||
}
|
||||
},
|
||||
autoConvertDelay: {
|
||||
name: {
|
||||
[Language.CN]: "自动转换延迟",
|
||||
[Language.EN]: "Auto Convert Delay"
|
||||
},
|
||||
desc: {
|
||||
[Language.CN]: "自动转换延迟,单位为毫秒",
|
||||
[Language.EN]: "Auto Convert Delay, in milliseconds"
|
||||
}
|
||||
},
|
||||
NonBoundaryCheckers: {
|
||||
name: {
|
||||
[Language.CN]: "非边界字符",
|
||||
|
|
@ -69,6 +79,7 @@ export class OneStepWikiLinkPluginSettingTab extends PluginSettingTab {
|
|||
display(): void {
|
||||
let { containerEl } = this;
|
||||
|
||||
this.settings = [];
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -116,11 +127,41 @@ export class OneStepWikiLinkPluginSettingTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.autoConvert = value;
|
||||
await this.plugin.saveSettings();
|
||||
if (value) {
|
||||
this.settings[2].value.settingEl.removeClass("setting-hide");
|
||||
} else {
|
||||
this.settings[2].value.settingEl.addClass("setting-hide");
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
this.settings.push(
|
||||
{
|
||||
key: this.labels.autoConvertDelay,
|
||||
value: new Setting(containerEl)
|
||||
.setName(this.labels.autoConvertDelay.name[this.plugin.settings.language])
|
||||
.setDesc(this.labels.autoConvertDelay.desc[this.plugin.settings.language])
|
||||
.addText((text) => {
|
||||
text.inputEl.type = "number";
|
||||
text
|
||||
.setValue(this.plugin.settings.autoConvertDelay.toString())
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.autoConvertDelay = Number(value);
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
if (this.plugin.settings.autoConvert) {
|
||||
this.settings[2].value.settingEl.removeClass("setting-hide");
|
||||
} else {
|
||||
this.settings[2].value.settingEl.addClass("setting-hide");
|
||||
}
|
||||
|
||||
|
||||
this.settings.push(
|
||||
{
|
||||
key: this.labels.NonBoundaryCheckers,
|
||||
|
|
|
|||
|
|
@ -71,4 +71,8 @@ One Step WikiLink Custome Css
|
|||
font-size: var(--font-ui-small);
|
||||
border-radius: var(--input-radius);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.setting-hide {
|
||||
display: none;
|
||||
}
|
||||
Loading…
Reference in a new issue