o
    �õ±jí  ã                   @  s€   d Z ddlmZ ddlmZ g d¢ZeZdddd„Zdddd„Zddd„Z	ddd„Z
ddd„Zddd„Zddd„Zd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           
      C  s¤   | j jj}| j j}|rN|jrP|j}|j}|j}|r|d }|jjd }d}||j	k rD| 
|¡}	||	 |k r>||	7 }|d7 }nn||j	k s*|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_height© r&   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/bindings/scroll.pyr      s&   





ù	ër   c           	      C  s    | j jj}| j j}|rL|jrN|j}|j}|r|d }td|jjd ƒ}d}|dkrB| 	|¡}|| |k r=||7 }|d8 }nn|dks)|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%   r&   r&   r'   r   8   s$   



ù	ìr   c                 C  ó   t | dd� dS )z8
    Same as ControlF, but only scroll half a page.
    T©r   N)r   ©r
   r&   r&   r'   r   V   ó   r   c                 C  r)   )z8
    Same as ControlB, but only scroll half a page.
    Tr*   N)r   r+   r&   r&   r'   r   ]   r,   r   c                 C  sv   | j jj}| j j}|r5|jr7|j}|j|j|j k r9|jj	|j
jkr,| j|j ¡ 7  _| jd7  _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!   r&   r&   r'   r	   d   s   
÷r	   c                 C  sž   | j jj}| j j}|rI|jrK|j}|jdkrM| | ¡ ¡}|jj	|j
d | |jj  }ttd|ƒƒD ]}| j|j ¡ 7  _q3| jd8  _dS dS dS dS )z
    scroll_offset -= 1
    r   r   N)r   r   r   r   r   r-   r   Úfirst_visible_liner   r#   r   r/   ÚbottomÚranger(   r   Úget_cursor_up_position)r
   r   r    r!   Úfirst_line_heightÚ	cursor_upÚ_r&   r&   r'   r   w   s,   

ÿþýÿ	ër   c                 C  sl   | j jj}| j j}|r2|jr4t|j ¡ |jd ƒ}||_|j 	|d¡|_
| j
|jjdd�7  _
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_liner-   r   r   r   Úget_start_of_line_position©r
   r   r    Ú
line_indexr&   r&   r'   Úscroll_page_down–   s   

ÿúr?   c                 C  st   | j jj}| j j}|r6|jr8tdt|j ¡ |jj	d ƒƒ}|j 
|d¡|_| j|jjdd�7  _d|_dS dS dS )zY
    Scroll page up. (Prefer the cursor at the bottom of the page, after scrolling.)
    r   r   Tr9   N)r   r   r   r   r   r(   Úminr2   r   r   r   r   r<   r-   r=   r&   r&   r'   Úscroll_page_up¨   s   

þ
ÿ
ñrA   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   r?   rA   r&   r&   r&   r'   Ú<module>   s    	




