separate active view logic into own function

This commit is contained in:
Alan Hamlett 2015-05-06 14:06:06 -07:00
parent d6d8bceca0
commit 3c4ceb95fa

View file

@ -173,6 +173,16 @@ def find_project_from_folders(folders, current_file):
return os.path.basename(folder) if folder else None return os.path.basename(folder) if folder else None
def is_view_active(view):
if view:
active_window = sublime.active_window()
if active_window:
active_view = active_window.active_view()
if active_view:
return active_view.buffer_id() == view.buffer_id()
return False
def handle_heartbeat(view, is_write=False): def handle_heartbeat(view, is_write=False):
window = view.window() window = view.window()
if window is not None: if window is not None:
@ -288,11 +298,11 @@ class WakatimeListener(sublime_plugin.EventListener):
handle_heartbeat(view, is_write=True) handle_heartbeat(view, is_write=True)
def on_selection_modified(self, view): def on_selection_modified(self, view):
if sublime.active_window().active_view().buffer_id() == view.buffer_id(): if is_view_active(view):
handle_heartbeat(view) handle_heartbeat(view)
def on_modified(self, view): def on_modified(self, view):
if sublime.active_window().active_view().buffer_id() == view.buffer_id(): if is_view_active(view):
handle_heartbeat(view) handle_heartbeat(view)