mirror of
https://github.com/lukasbach/obsidian-code-files.git
synced 2026-07-22 07:40:30 +00:00
allow creating new css snippetsd(#11)
This commit is contained in:
parent
d015aadb35
commit
fb5dfcd874
2 changed files with 21 additions and 2 deletions
BIN
css-files.gif
BIN
css-files.gif
Binary file not shown.
|
Before Width: | Height: | Size: 438 KiB After Width: | Height: | Size: 639 KiB |
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue