
    Mh                    r    d Z ddlmZ ddlmZ g dZeZdddZdddZddZ	ddZ
ddZddZddZddZdS )z
Key bindings, for scrolling up and down through pages.

This are separate bindings, because GNU readline doesn't have them, but
they are very useful for navigating through long multiline buffers, like in
Vi, Emacs, etc...
    )annotations)KeyPressEvent)scroll_forwardscroll_backwardscroll_half_page_upscroll_half_page_downscroll_one_line_upscroll_one_line_downFeventEhalfboolreturnNonec                t   | j         j        j        }| j         j        }|r|j        r|j        }|j        }|j        }|r|dz  }|j        j        dz   }d}||j	        k     r5|
                    |          }	||	z   |k     r||	z  }|dz  }nn||j	        k     5|j                            |d          |_        dS dS dS )z
    Scroll window down.
          r   N)applayoutcurrent_windowcurrent_bufferrender_info
ui_contentwindow_heightdocumentcursor_position_row
line_countget_height_for_linetranslate_row_col_to_indexcursor_position)
r   r   wbinfor   scroll_heightyheightline_heights
             j/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyr   r      s    		'A	 A HQ] H}_
 * 	 aM J*Q.*'''22155K#m33+%Q *''' JAA!QGG+H H H H    c                n   | j         j        j        }| j         j        }|r|j        r|j        }|j        }|r|dz  }t          d|j        j        dz
            }d}|dk    r0|	                    |          }||z   |k     r||z  }|dz  }nn|dk    0|j        
                    |d          |_        dS dS dS )z
    Scroll window up.
    r   r   r   N)r   r   r   r   r   r   maxr   r   r   r   r    )	r   r   r!   r"   r#   r$   r%   r&   r'   s	            r(   r   r   8   s     		'A	 A HQ] H} * 	 aM 1:1A566!ee22155K#m33+%Q !ee JAA!QGG)H H H Hr)   c                (    t          | d           dS )z8
    Same as ControlF, but only scroll half a page.
    Tr   N)r   r   s    r(   r   r   V   s     5t$$$$$$r)   c                (    t          | d           dS )z8
    Same as ControlB, but only scroll half a page.
    Tr-   N)r   r.   s    r(   r   r   ]   s     E%%%%%%r)   c                >   | j         j        j        }| j         j        }|ry|j        rt|j        }|j        |j        |j        z
  k     rW|j        j	        |j
        j        k    r'|xj        |j                                        z  c_        |xj        dz  c_        dS dS dS dS )z
    scroll_offset += 1
    r   N)r   r   r   r   r   vertical_scrollcontent_heightr   r    r%   configured_scroll_offsetstopr   get_cursor_down_position)r   r!   r"   r#   s       r(   r
   r
   d   s     		'A	 A 	'= 	'=D 4#69K#KKK')T-K-OOO%%)L)L)N)NN%%!!Q&!!!!	' 	'	' 	' LKr)   c                   | j         j        j        }| j         j        }|r|j        r|j        }|j        dk    r|                    |                                          }|j        j	        |j
        dz
  |z
  |j        j        z
  z
  }t          t          d|                    D ])}|xj        |j                                        z  c_        *|xj        dz  c_        dS dS dS dS )z
    scroll_offset -= 1
    r   r   N)r   r   r   r   r   r1   r   first_visible_liner    r%   r   r3   bottomranger+   r   get_cursor_up_position)r   r!   r"   r#   first_line_height	cursor_up_s          r(   r	   r	   w   s    		'A	 A '= 	'=D 1$$$($<$<T=T=T=V=V$W$W! 02&'( 4;<	 s1i0011 M MA%%)J)J)L)LL%%% !!Q&!!!!+' '	' 	' %$r)   c                X   | j         j        j        }| j         j        }|r|j        rt          |j                                        |j        dz             }||_        |j        	                    |d          |_
        |xj
        |j                            d          z  c_
        dS dS dS )zX
    Scroll page down. (Prefer the cursor at the top of the page, after scrolling.)
    r   r   Tafter_whitespaceN)r   r   r   r   r   r+   last_visible_liner1   r   r   r    get_start_of_line_positionr   r!   r"   
line_indexs       r(   scroll_page_downrE      s     		'A	 A 
Q] 
88::A<MPQ<QRR
&JAA*aPP	QZBB! C 
 
 	

 
 
 
r)   c                ~   | j         j        j        }| j         j        }|r|j        rt          dt          |j                                        |j        j	        dz
                      }|j        
                    |d          |_        |xj        |j                            d          z  c_        d|_        dS dS dS )zY
    Scroll page up. (Prefer the cursor at the bottom of the page, after scrolling.)
    r   r   Tr?   N)r   r   r   r   r   r+   minr7   r   r   r   r    rB   r1   rC   s       r(   scroll_page_uprH      s     		'A	 A Q]  0022AJ4RUV4VWW
 


 JAA*aPP	QZBB! C 
 
 	
    r)   N)F)r   r   r   r   r   r   )r   r   r   r   )__doc__
__future__r   (prompt_toolkit.key_binding.key_processorr   __all__r   r   r   r   r   r
   r	   rE   rH    r)   r(   <module>rN      s    # " " " " " B B B B B B   H H H H H>H H H H H<% % % %& & & &' ' ' '&' ' ' '>
 
 
 
$     r)   