rabirabirara / obsidian-jelly-snippets

A simple text snippets plugin for Obsidian.md. BACKUP SNIPPETS BEFORE UPDATING.
MIT License
24 stars 0 forks source link

Snippet trigger will overwrite all the way to first occurrence of snippet lhs. #5

Closed rabirabirara closed 1 year ago

rabirabirara commented 1 year ago

If you have a |+| b and the following text:

a, a, a, a, a, a<cursor>

Triggering the snippet will give you:

b

Which is certainly not intended behavior. This bug stems from the searchSnippet method used to find matches. This is because each search will return multiple matches for each word of a multi-word lhs. For example, with "a new line |+| anl", the search results will contain three matches: "a", "new", and "line". Hastily I just had the search use the first match to the last and replace all of that selection, but evidently if the lhs occurs earlier in the line it will replace all up to the first instance of the lhs.

This should be fixable by actually scanning backwards and matching with the snippet lhs in reverse.

rabirabirara commented 1 year ago

https://github.com/rabirabirara/obsidian-jelly-snippets/commit/90311f1b325c03d17ff55fc271df96cb195ce7cd should fix this.