#NEWLINE# def _scroll_when_linewrapping( self , ui_content , width , height , cli ) : #NEWLINE# #INDENT# '\n        Scroll to make sure the cursor position is visible and that we maintain\n        the requested scroll offset.\n\n        Set `self.horizontal_scroll/vertical_scroll`.\n        ' #NEWLINE# scroll_offsets_bottom = self . scroll_offsets . bottom #NEWLINE# scroll_offsets_top = self . scroll_offsets . top #NEWLINE# self . horizontal_scroll = 0 #NEWLINE# if ( ui_content . get_height_for_line ( ui_content . cursor_position . y , width ) > ( height - scroll_offsets_top ) ) : #NEWLINE# #INDENT# line = explode_tokens ( ui_content . get_line ( ui_content . cursor_position . y ) ) #NEWLINE# text_before_cursor = token_list_to_text ( line [ : ( ui_content . cursor_position . x + 1 ) ] ) #NEWLINE# text_before_height = UIContent . get_height_for_text ( text_before_cursor , width ) #NEWLINE# self . vertical_scroll = ui_content . cursor_position . y #NEWLINE# self . vertical_scroll_2 = min ( ( text_before_height - 1 ) , self . vertical_scroll_2 ) #NEWLINE# self . vertical_scroll_2 = max ( 0 , ( text_before_height - height ) , self . vertical_scroll_2 ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . vertical_scroll_2 = 0 #NEWLINE# #UNINDENT# def get_min_vertical_scroll( ) : #NEWLINE# #INDENT# used_height = 0 #NEWLINE# prev_lineno = ui_content . cursor_position . y #NEWLINE# for lineno in range ( ui_content . cursor_position . y , ( - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# used_height += ui_content . get_height_for_line ( lineno , width ) #NEWLINE# if ( used_height > ( height - scroll_offsets_bottom ) ) : #NEWLINE# #INDENT# return prev_lineno #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prev_lineno = lineno #NEWLINE# #UNINDENT# #UNINDENT# return 0 #NEWLINE# #UNINDENT# def get_max_vertical_scroll( ) : #NEWLINE# #INDENT# prev_lineno = ui_content . cursor_position . y #NEWLINE# used_height = 0 #NEWLINE# for lineno in range ( ( ui_content . cursor_position . y - 1 ) , ( - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# used_height += ui_content . get_height_for_line ( lineno , width ) #NEWLINE# if ( used_height > scroll_offsets_top ) : #NEWLINE# #INDENT# return prev_lineno #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prev_lineno = lineno #NEWLINE# #UNINDENT# #UNINDENT# return prev_lineno #NEWLINE# #UNINDENT# def get_topmost_visible( ) : #NEWLINE# #INDENT# '\n            Calculate the upper most line that can be visible, while the bottom\n            is still visible. We should not allow scroll more than this if\n            `allow_scroll_beyond_bottom` is false.\n            ' #NEWLINE# prev_lineno = ( ui_content . line_count - 1 ) #NEWLINE# used_height = 0 #NEWLINE# for lineno in range ( ( ui_content . line_count - 1 ) , ( - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# used_height += ui_content . get_height_for_line ( lineno , width ) #NEWLINE# if ( used_height > height ) : #NEWLINE# #INDENT# return prev_lineno #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prev_lineno = lineno #NEWLINE# #UNINDENT# #UNINDENT# return prev_lineno #NEWLINE# #UNINDENT# topmost_visible = get_topmost_visible ( ) #NEWLINE# self . vertical_scroll = max ( self . vertical_scroll , min ( topmost_visible , get_min_vertical_scroll ( ) ) ) #NEWLINE# self . vertical_scroll = min ( self . vertical_scroll , get_max_vertical_scroll ( ) ) #NEWLINE# if ( not self . allow_scroll_beyond_bottom ( cli ) ) : #NEWLINE# #INDENT# self . vertical_scroll = min ( self . vertical_scroll , topmost_visible )