
    f'                       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        P/var/www/cvtools/html/venv/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__4   s     	"$[1r   c                    | j                   j                   d| j                  d| j                  d| j                  dS )N(z, direction=z, ignore_case=))	__class__r   r   r   r    )r$   s    r   __repr__zSearchState.__repr__>   s?    ..))*!DII=T^^DVVdeieueudxxyzzr   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__A   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   "   sU     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   r6   r8   s        r   r   r   P   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   r6   search_target_buffer_controlr8   r;   values_get_reverse_search_linksr:   bufferresetr   
NAVIGATIONr=   r>   )r?   r6   r8   s      r   r   r   w   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   r3   NF)include_current_positioncount)r	   r   r6   r4   r   r7   r5   rA   r9   r   rD   r   apply_search)r   rI   r6   r   search_controlprev_controlr9   direction_changeds           r   do_incremental_searchrN      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   r3   NT)rH   )r   r6   r7   rA   r4   r   r5   r9   rD   r   rJ   append_to_historyr   )r6   rK   target_buffer_controlr   r9   s        r   accept_searchrR      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)r6   r8   r?   s      r   rC   rC      s>     6<5H5H5N5N5P1!> 	--  s   /)r?   BufferControl | Noner   r   r.   r/   r#   )r?   rU   r.   r/   )r   )r   r   rI   intr.   r/   )r.   r/   )r6   r   r.   z(dict[BufferControl, SearchBufferControl])r0   
__future__r   enumr   typingr   application.currentr   filtersr   r	   r
   key_binding.vi_stater   r4   r   r   prompt_toolkit.layout.layoutr   __all__r   r   r   r   r   rN   rR   rC   r   r   r   <module>r_      s    #    ( : : +Q3d 
+
 +
^ ,0!0!8!8$9($9$9 
$9N9>
B'D		-	r   