ArianaKhit / text-snippets-obsidian

Snippets plugin for obsidian
177 stars 21 forks source link

Multiline snippets in folders #45

Open TinyAtoms opened 2 years ago

TinyAtoms commented 2 years ago

Here is a working proof of concept of what I wanted and how multiline snippets could be implemented. It is not in a state where it should be merged yet. No error handling to speak of, no tests, etc. I do want to know what you think of this method of implementation, and suggestions on how you would do it. My alternative method was going to be using something like using something like

file : TAbstractFile = this.app.metadataCache.getFirstLinkpathDest(this,settings.multilineFolder +selectedText, "");
newstr = this.app.vault.cachedRead(file).then((content) => this.mlSnippets[file.basename] = content);
if (newStr == null) newstr = ""

in findSnippet. My reasoning for not doing it that way is that it might produce noticable delays after trying to insert.

ArianaKhit commented 2 years ago

My reasoning for not doing it that way is that it might produce noticable delays after trying to insert.

Can multiline snippets be loaded to snippets variable in settings, so delays will be less?

TinyAtoms commented 2 years ago

You could, but then you'd lose the simplicity of that, and would be doing something like what I'm doing in the PR. The simplicity in directly reading it from the file is that you don't have to monitor the multiline snippet folder. As soon as you move it in memory, you'd have to make sure that your in-memory copy reflects that folder, so you'd have to monitor it.

ArianaKhit commented 2 years ago

Then I think this method will be just fine, you can use one of the latest versions of the code, without errors while loading the plugin in Live Preview, if you want to test it

willow512 commented 2 years ago

Is there progress on this issue? I'm very much looking forward to use this feature. :)