Question

on_activated is supposed to be called "when a view gains input focus" (ST3 API docs). When I switch to a different project/workspace with cmd+control+p in ST3, on_activated gets called for all views in the working space/project. So it might be called 10 times or more. I find that behavior unexpected and would like to just get one call for the currently visible view. So why not just once for the view that gains input focus with the project switch? Any workarounds?

Thanks!

EDIT

Here is the code.

import sublime_plugin

class TestPlugin(sublime_plugin.EventListener):
    count = 0

    def on_activated(self, view):
        self.count += 1
        print('"on_activated" event fired %ith time!' % self.count)
Was it helpful?

Solution

Check whether the currently activated view is the one you want to.

import sublime_plugin

class TestPlugin(sublime_plugin.EventListener):
    count = 0

    def on_activated(self, view):
        if self.view.window().active_view().id() == view.id():
            print('"on_activated" successfully fired!')
        else:
            self.count += 1
            print('"on_activated": %i unsuccessful fired.' % self.count)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top