Sublime Forum

API Request: set_active_view_in_group

#1

We have an API for getting the active view (window.active_view_in_group(group)) and it would be nice to have a corresponding set_active_view_in_group(view, group). I encountered a situation today where it would be handy:

I’m working on a plugin to open associated files (code/test pairs) which opens a file and then potentially moves it to a different group. If the reference file (the one open initially) has a neighbor to the right, that neighbor is active in the view after the associated file is moved. To work around this, I did this:

associated_view = self.window.open_file(path_to_associated_file)
self.window.set_view_index(associated_view, new_group, new_index)
self.window.focus_view(existing_view)
self.window.focus_view(associated_view)

If that doesn’t make sense, I can create a short screencast illustrating the behavior. Since window.open_file activates the newly opened file, it is already active in the target group. If there were a way to focus a view in a particular group, that would have saved me a call. It could have looked like

current_group, current_index = self.window.get_view_index(existing_view)
associated_view = self.window.open_file(path_to_associated_file)
self.window.focus_view(existing_view, current_group)

Thoughts?

0 Likes