allow creating new css snippetsd(#11)

This commit is contained in:
Lukas Bach 2023-10-03 17:43:36 +02:00
parent d015aadb35
commit fb5dfcd874
2 changed files with 21 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 438 KiB

After

Width:  |  Height:  |  Size: 639 KiB

View file

@ -8,12 +8,31 @@ export class ChooseCssFileModal extends SuggestModal<string> {
}
getSuggestions(query: string): string[] {
return this.cssFiles.filter((item) =>
const files = this.cssFiles.filter((item) =>
item.toLowerCase().includes(query.toLowerCase())
);
if (query) {
return [...files, `Create new snippet "${query}.css"`];
}
return files;
}
onChooseSuggestion(item: string): any {
async onChooseSuggestion(item: string) {
const maybeCreateFile = item.match(/Create new snippet "(.*)\.css"/);
if (maybeCreateFile?.[1]) {
const path = `${this.app.vault.configDir}/snippets/${maybeCreateFile[1]}.css`;
await this.plugin.app.vault.adapter.write(path, "");
CodeEditorView.openFile(
// @ts-ignore
new TFile(this.app.vault, path),
this.plugin
);
new Notification("Make sure to enable new snippet in options.");
return;
}
CodeEditorView.openFile(
// @ts-ignore
new TFile(this.app.vault, item),