
    @Neo                        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e          Z G d d          Zdej        fd dZd!d"dZd#d$dZd%dZ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                      e Zd ZdZdZdS )r   FORWARDBACKWARDN)__name__
__module____qualname__r   r        /home/feoh/.cache/pypoetry/virtualenvs/veilid-python-play-bIboZq2W-py3.11/lib/python3.11/site-packages/prompt_toolkit/search.pyr   r      s        GHHHr   r   c                  @    e Zd ZdZdZdej        dfddZddZ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                J    || _         || _        t          |          | _        d S N)r   r   r
   r    )selfr   r   r    s       r   __init__zSearchState.__init__3   s(     	"$[11r   c                d    d                     | j        j        | j        | j        | j                  S )Nz*{}({!r}, direction={!r}, ignore_case={!r}))format	__class__r   r   r   r    )r'   s    r   __repr__zSearchState.__repr__=   s2    ;BBN#IN	
 
 	
r   c                    | j         t          j        k    rt          j        }nt          j        }t	          | j        || j                  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   s     r   
__invert__zSearchState.__invert__E   sI    
 >_555'/II'0IiT=M
 
 
 	
r   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   !   st          5I %4%<$)	2 2 2 2 2
 
 
 

 
 
 
 
 
r   r   Nbuffer_controlBufferControl | Noner   r#   r$   c                P   ddl m} | t          | |          sJ t                      j        }| t          |j        |          sdS |j        } | j        }|rO|| 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   INSERTvi_state
input_mode)r1   r   r   r7   r9   s        r   r   r   T   s     =<<<<<!Z%N%N!!!YYF &0-@@ 	F/ +@ 
909#- 	*+++ 6D12 )2(8		%%%
9 
9r   c                n   t                      j        }| |j        } | dS | j        }n2| |j                                        v sJ t          |          |          }|                    |            |!|j        |= |j        	                                 t          j        t                      j        _        dS )z9
    Stop search through the given `buffer_control`.
    N)r   r7   search_target_buffer_controlr9   r<   values_get_reverse_search_linksr;   bufferresetr   
NAVIGATIONr>   r?   )r1   r7   r9   s      r   r   r   {   s     YYF<! F . D!4!;!;!=!===== 9& A A. Q LL   ( 56 	$**,,, %.$8GII!!!r   countintc                6   t                      sJ t                      j        }ddlm} |j        }t          ||          sdS |j        }|dS |j        }|j	        | k    }|j
        j        |_        | |_	        |s|j
                            |d|           dS dS )z7
    Apply search, but keep search buffer focused.
    r   r4   NF)include_current_positionrG   )r	   r   r7   r5   r   r8   r6   rA   r:   r   rD   r   apply_search)r   rG   r7   r   search_controlprev_controlr:   direction_changeds           r   do_incremental_searchrO      s     >>YYF =<<<<<+Nnm44 6L,L %.);&-2L&L  
((5 	) 	
 	
 	
 	
 	

 
r   c                 P   t                      j        } | j        }| j        }ddlm} t          ||          sdS |dS |j        }|j        j	        r|j        j	        |_	        |j        
                    |d           |j                                         t          |           dS )zL
    Accept current search query. Focus original `BufferControl` again.
    r   r4   NT)rJ   )r   r7   r8   rA   r5   r   r6   r:   rD   r   rK   append_to_historyr   )r7   rL   target_buffer_controlr   r:   s        r   accept_searchrS      s     YYF+N"?<<<<<<nm44 $(5L ! 7*16  --t .   
 ++--- %&&&&&r   r7   r   (dict[BufferControl, SearchBufferControl]c                H    d | j                                         D             S )zC
    Return mapping from BufferControl to SearchBufferControl.
    c                    i | ]\  }}||	S r   r   ).0r9   r1   s      r   
<dictcomp>z-_get_reverse_search_links.<locals>.<dictcomp>   s0       1!> 	-  r   )r<   items)r7   s    r   rC   rC      s2     5;5H5N5N5P5P   r   )r1   r2   r   r   r#   r$   r&   )r1   r2   r#   r$   )r   )r   r   rG   rH   r#   r$   )r#   r$   )r7   r   r#   rT   )r/   
__future__r   enumr   typingr   application.currentr   filtersr   r	   r
   key_binding.vi_stater   r5   r   r   prompt_toolkit.layout.layoutr   __all__r   r   r   r   r   rO   rS   rC   r   r   r   <module>rb      s    # " " " " "                   ( ( ( ( ( ( : : : : : : : : : : + + + + + + 4QQQQQQQQ333333      d   
0
 0
 0
 0
 0
 0
 0
 0
h ,0!0!8$9 $9 $9 $9 $9N9 9 9 9 9>
 
 
 
 
B' ' ' 'D	 	 	 	 	 	r   