ArianaKhit / text-snippets-obsidian

Snippets plugin for obsidian
177 stars 21 forks source link

[Feature Request] Add Multiple cursor position #54

Open Archie-2021 opened 1 year ago

Archie-2021 commented 1 year ago

It would be awesome if you add multiple Cursor position to jump to not just one end one.

Just found your Plugin, Thank you for this, really helpful

jeansordes commented 1 year ago

Can you give an exemple ? I'm not sure to see what you mean

Archie-2021 commented 1 year ago

Right now there is only one jump point, like you put $end$ somewhere in the snippet, run it and it jumps into that location. But what if I want to jump to nextplace after that? Like how other snippet /template stuff work. Like in there is <% tp.file.cursor() %> in templater and which jumps to 1 at the launch of snippet and then we can jump to 2 and 3 ... with a press of a hotkey.

jeansordes commented 1 year ago

Can you give an exemple though ?

Your explanation was already clear enough in the first place, but I don't see any practical case where you would need multiple cursors, that's why I was curious to see if you had a concrete exemple in mind

jeansordes commented 1 year ago

I think I found an exemple, correct me if I'm wrong

hello : Hello $1:name$,$nl$how is $2:name$ doing ? $end$

And when you call it, your cursor would go to the first cursor, with the text "name" selected, so that when you type, it will replace it with what you want, and when you hit tab it will go to the next cursor place, and do the same things, and when you hit tab again, it goes to the $end$ place

By looking at the documentation of VSCode I think I understand better how it is useful to have multiple cursors, but when I look at how the current Obsidian Snippet plugin works, it would be very challenging to implement it :/

Archie-2021 commented 1 year ago

Yeah that is a good example. It is very standard in most snippet programs I have seen, like Templater in obsidian or UltiSnips in vim. Altho tbh, I don't have a use case right now, I use Templater to fill forms and such and not got used to fully implement this plugin beside some limited cases which text expansion is much faster.

So it is a nice thing to have but not urgent and I understand that is not easy to implement technically.

Thank you.

jeansordes commented 1 year ago

… I just discovered that what you described was already implemented in the plugin. I feel so dumb.

See $tb$

So if I rewrite the exemple I gave but with the syntax of the plugin, it goes like this :

hello : Hello $tb$,$nl$how is $tb$ doing ? $tb$

It will replace $tb$ with $tb$, and when you'll hit Tab, it will jump to the next $tb$, so that you can type what you want.

And, just in case, the documentation says that you should not combine it with $end$ But other than that, it works pretty well actually ( >ᴗ<)

Sorry for telling you that it was not possible 😬

Archie-2021 commented 1 year ago

I am trying to test it with the example you used above but using tab key even in sandbox vault causes the whole line to indent instead of jumping to the next position. Do you know how to fix that?

jeansordes commented 1 year ago

Ah, you have the same problem than others

I've described a solution for that in the following comment : https://github.com/ArianaKhit/text-snippets-obsidian/issues/47#issuecomment-1292384245

Archie-2021 commented 1 year ago

Ah, you have the same problem than others

I've described a solution for that in the following comment : #47 (comment)

Thank for the help, hope the author soon accept the your pull request.