Skip to content

Instantly share code, notes, and snippets.

@acarabott
Created November 1, 2014 19:56
Show Gist options
  • Save acarabott/97e8d68ac1cf3c822c44 to your computer and use it in GitHub Desktop.
Save acarabott/97e8d68ac1cf3c822c44 to your computer and use it in GitHub Desktop.
Sublime Text 3 API, check if view scroll position is at bottom
# useful for implementing output view auto scrolling, only when at the bottom
def view_is_at_bottom(view):
layout_h = view.layout_extent()[1]
view_h = view.viewport_extent()[1]
view_y = view.viewport_position()[1]
line_h = view.line_height()
view_taller_than_content = layout_h <= view_h
at_bottom_of_content = view_y + view_h >= layout_h - line_h
return view_taller_than_content or at_bottom_of_content
@acarabott
Copy link
Author

This is actually quite slow, a less accurate but more efficient way is

def view_is_at_bottom(self):
    return self.view.visible_region().b + 100 > self.view.size()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment