Sublime Forum

How can I tell when I'm inside a panel?

#1

I often need to switch back and forth between two files, and I have a very simple command to jump back to the last view.

import sublime
import sublime_plugin

'''
Go back to the last view.  Useful for jumping back and forth between two views
'''

last_view = None

class LastViewRecorder(sublime_plugin.EventListener):
	"""Keep track of last view
	"""

	def on_deactivated(self, view):
		"""When view is deactivated, record it 
		"""
		global last_view
		last_view = view

class LastViewCommand(sublime_plugin.WindowCommand):
	"""Go back to last view. Useful for jumping back and forth between two views
	   with a single key press
	"""

	def run(self):
		global last_view
		if last_view is not None:
			self.window.focus_view(last_view)

It works fine, except when I bring up the console or a quick panel. I think the problem is I need to detect when I’m in the console or quick panel and not record the view. How can I do that?

0 Likes

#2

You can use view.settings().get(‘is_widget’)

0 Likes

Switch focus from panel or overlay to text of document from within plugin