Sublime Forum

How to cycle through position with Tab key

#1

I am writing a simple plugin which pastes multiple lines in one joined by a separator.
The plugin and its description can be found here: https://github.com/OoDeLally/MultiCaretPaste.

Currently, the final carets are places between the items.

Now, I would like to be able to cycle (pressing TAB) through different caret configuration: before each item, between items, after each item. I wrote a pictued example of it on that stackoverflow topic: https://stackoverflow.com/questions/46619412/sublime-text-paste-joined-multicursor

A similar behavior already exists with snippets fields, where the user can cycle through $0, $1, $2, etc.

Do you know if its doable with the plugin api ?

0 Likes

#2

Yes it is possible and I have added it to MultiEditUtils. If you have it installed you can just run window.run_command("selection_fields") in your plugin.

1 Like

#3

The PowerCursors package also does something like this already (you can see it in action in the animated GIF).

0 Likes

#4

@r-stein Thank you, this is an amazing plugin that I will definitely use! :slight_smile:
I will try to add the selection_field into my plugin.

@OdatNurd I tried it, it is similar, but I could not find a way to have the same behavior with this plugin.

Thanks guys

0 Likes

#5

PowerCursors also has this functionality, but it uses different keybindings (I don’t think you can have the same behavior by changing the keybindings, because there is no context to pop it if you tab over the last field). My main goal while developing that feature was to make it as intuitive as possible and limit the number of keybindings you need to remember.
PowerCursors on the other hand seems to be a port from emacs, where you usually have a lot of kbds to learn for each package you install and have the full control what is happening as an advantage (you can also have that control by setting the kbds explicit with my feature).

0 Likes

#6

Hi @r-stein, thank you for your reply.
I believe by the first PowerCursors you mentioned, you meant MultiEditUtils?

I reviewed both of those packages, but wasn’t able to figure out how to obtain the same behaviour.

I took some inspiration from your code, and created what I wanted, you can see it used here:

Its working fine!

However there is something I would like to do, but I dont know whether it is possible.
Let’s say I have an empty region somewhere. When doing self.view.sel().add(myEmptyRegion), the following written characters are inserted after/before the region (because an empty is considered as a simple caret), while I would like it to extend the region (therefore un-empty it). Any hack you are aware of for that?

0 Likes