o
    Zho                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZ er:dd	lmZmZ dd
lmZ g dZG dd deZG dd dZdejfd%ddZd&d'ddZd(d)ddZd*ddZd+d#d$ZdS ),z
Search operations.

For the key bindings implementation with attached filters, check
`prompt_toolkit.key_binding.bindings.search`. (Use these for new key bindings
instead of calling these function directly.)
    )annotations)Enum)TYPE_CHECKING   )get_app)FilterOrBoolis_searching	to_filter)	InputMode)BufferControlSearchBufferControl)Layout)SearchDirectionstart_searchstop_searchc                   @  s   e Zd ZdZdZdS )r   FORWARDBACKWARDN)__name__
__module____qualname__r   r    r   r   L/var/www/html/lang_env/lib/python3.10/site-packages/prompt_toolkit/search.pyr      s    r   c                   @  s<   e Zd ZdZdZdejdfdddZdddZdddZ	dS )SearchStateaw  
    A search 'query', associated with a search field (like a SearchToolbar).

    Every searchable `BufferControl` points to a `search_buffer_control`
    (another `BufferControls`) which represents the search field. The
    `SearchState` attached to that search field is used for storing the current
    search query.

    It is possible to have one searchfield for multiple `BufferControls`. In
    that case, they'll share the same `SearchState`.
    If there are multiple `BufferControls` that display the same `Buffer`, then
    they can have a different `SearchState` each (if they have a different
    search control).
    text	directionignore_case Fr   strr   r   r   r   returnNonec                 C  s   || _ || _t|| _d S N)r   r   r	   r   )selfr   r   r   r   r   r   __init__3   s   zSearchState.__init__c                 C  s   d | jj| j| j| jS )Nz*{}({!r}, direction={!r}, ignore_case={!r}))format	__class__r   r   r   r   )r"   r   r   r   __repr__=   s   zSearchState.__repr__c                 C  s,   | j tjkr
tj}ntj}t| j|| jdS )zm
        Create a new SearchState where backwards becomes forwards and the other
        way around.
        r   )r   r   r   r   r   r   r   )r"   r   r   r   r   
__invert__E   s   
zSearchState.__invert__N)r   r   r   r   r   r   r   r    )r   r   )r   r   )
r   r   r   __doc__	__slots__r   r   r#   r&   r'   r   r   r   r   r   !   s    

r   Nbuffer_controlBufferControl | Noner   r   r    c                 C  s   ddl m} | du st| |sJ t j}| du r$t|j|s!dS |j} | j}|r?|| j_|	| | |j
|< tjt j_dS dS )z
    Start search through the given `buffer_control` using the
    `search_buffer_control`.

    :param buffer_control: Start search for this `BufferControl`. If not given,
        search through the current control.
    r   r   N)prompt_toolkit.layout.controlsr   
isinstancer   layoutcurrent_controlsearch_buffer_controlsearch_stater   focussearch_linksr
   ZINSERTvi_state
input_mode)r*   r   r   r/   r1   r   r   r   r   T   s   

r   c                 C  s|   t  j}| du r|j} | du rdS | j}n| |j v sJ t||  }||  |dur6|j|= |j	  t
jt  j_dS )z9
    Stop search through the given `buffer_control`.
    N)r   r/   search_target_buffer_controlr1   r4   values_get_reverse_search_linksr3   bufferresetr
   Z
NAVIGATIONr5   r6   )r*   r/   r1   r   r   r   r   {   s   

r   countintc                 C  s   t  sJ t j}ddlm} |j}t||sdS |j}|du r"dS |j}|j	| k}|j
j|_| |_	|s?|j
j|d|d dS dS )z7
    Apply search, but keep search buffer focused.
    r   r,   NF)include_current_positionr<   )r   r   r/   r-   r   r0   r.   r7   r2   r   r:   r   apply_search)r   r<   r/   r   search_controlZprev_controlr2   Zdirection_changedr   r   r   do_incremental_search   s$   




rA   c                  C  sx   t  j} | j}| j}ddlm} t||sdS |du rdS |j}|jj	r)|jj	|_	|jj
|dd |j  t| dS )zL
    Accept current search query. Focus original `BufferControl` again.
    r   r,   NT)r>   )r   r/   r0   r7   r-   r   r.   r2   r:   r   r?   Zappend_to_historyr   )r/   r@   Ztarget_buffer_controlr   r2   r   r   r   accept_search   s    


rB   r/   r   (dict[BufferControl, SearchBufferControl]c                 C  s   dd | j  D S )zC
    Return mapping from BufferControl to SearchBufferControl.
    c                 S  s   i | ]\}}||qS r   r   ).0r1   r*   r   r   r   
<dictcomp>   s    z-_get_reverse_search_links.<locals>.<dictcomp>)r4   items)r/   r   r   r   r9      s   r9   )r*   r+   r   r   r   r    r!   )r*   r+   r   r    )r   )r   r   r<   r=   r   r    )r   r    )r/   r   r   rC   )r(   
__future__r   enumr   typingr   Zapplication.currentr   filtersr   r   r	   Zkey_binding.vi_stater
   r-   r   r   Zprompt_toolkit.layout.layoutr   __all__r   r   r   r   r   rA   rB   r9   r   r   r   r   <module>   s(    4'
!"