
    VVfo                       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y)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y)r   FORWARDBACKWARDN)__name__
__module____qualname__r   r        ^/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/prompt_toolkit/search.pyr   r      s    GHr   r   c                  V    e Zd ZdZdZdej                  df	 	 	 	 	 	 	 d	dZd
dZddZ	y)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 Fc                @    || _         || _        t        |      | _        y N)r   r   r
   r    )selfr   r   r    s       r   __init__zSearchState.__init__3   s     	"$[1r   c                    dj                  | 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__=   s9    ;BBNN##IINN	
 	
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   sJ    
 >>_555'//I'00IiT=M=M
 	
r   N)r   strr   r   r    r   returnNone)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   Nc                p   ddl m} | t        | |      sJ t               j                  }| #t        |j
                  |      sy|j
                  } | j                  }|rY|| j                  _        |j                  |       | |j                  |<   t        j                  t               j                  _        yy)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)buffer_controlr   r   r5   r7   s        r   r   r   T   s     =!Z%NNNYF &00-@// +@@09##- 	*+ 6D12 )2(8(8	% r   c                   t               j                  }| |j                  } | y| j                  }n,| |j                  j                         v sJ t        |      |    }|j                  |        |'|j                  |= |j                  j                          t        j                  t               j                  _        y)z9
    Stop search through the given `buffer_control`.
    N)r   r5   search_target_buffer_controlr7   r:   values_get_reverse_search_linksr9   bufferresetr   
NAVIGATIONr<   r=   )r>   r5   r7   s      r   r   r   {   s     YF<<!  . D D!4!4!;!;!==== 9& A. Q LL ( 56 	$$**, %.$8$8GI!r   c                \   t               sJ t               j                  }ddlm} |j
                  }t        ||      sy|j                  }|y|j                  }|j                  | k7  }|j                  j                  |_        | |_	        |s|j                  j                  |d|       yy)z7
    Apply search, but keep search buffer focused.
    r   r2   NF)include_current_positioncount)r	   r   r5   r3   r   r6   r4   r@   r8   r   rC   r   apply_search)r   rH   r5   r   search_controlprev_controlr8   direction_changeds           r   do_incremental_searchrM      s     >>YF =++Nnm466L,,L %..);&--22L&L ((5 	) 	
 r   c                    t               j                  } | j                  }| j                  }ddlm} t        ||      sy|y|j                  }|j                  j                  r|j                  j                  |_	        |j                  j                  |d       |j                  j                          t        |       y)zL
    Accept current search query. Focus original `BufferControl` again.
    r   r2   NT)rG   )r   r5   r6   r@   r3   r   r4   r8   rC   r   rI   append_to_historyr   )r5   rJ   target_buffer_controlr   r8   s        r   accept_searchrQ      s     YF++N"??<nm4$(55L !!*1166   --t . 
 ++- %&r   c                j    | j                   j                         D ci c]  \  }}||
 c}}S c c}}w )zC
    Return mapping from BufferControl to SearchBufferControl.
    )r:   items)r5   r7   r>   s      r   rB   rB      s>     6<5H5H5N5N5P1!> 	--  s   /)r>   BufferControl | Noner   r   r-   r.   r#   )r>   rT   r-   r.   )r   )r   r   rH   intr-   r.   )r-   r.   )r5   r   r-   z(dict[BufferControl, SearchBufferControl])r/   
__future__r   enumr   typingr   application.currentr   filtersr   r	   r
   key_binding.vi_stater   r3   r   r   prompt_toolkit.layout.layoutr   __all__r   r   r   r   r   rM   rQ   rB   r   r   r   <module>r^      s    #    ( : : +Q3d 
0
 0
h ,0!0!8!8$9($9$9 
$9N9>
B'D		-	r   