o
    �õ±j?  ã                   @  sd   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ dgZeZddd„ZdS )zD
Key bindings for auto suggestion (for fish-style auto suggestion).
é    )ÚannotationsN)Úget_app)Ú	ConditionÚ
emacs_mode)ÚKeyBindings)ÚKeyPressEventÚload_auto_suggest_bindingsÚreturnr   c                  C  sh   t ƒ } | j}tddd„ƒ}|d|d�|d|d�|d|d�ddd„ƒƒƒ}|dd|t@ d�ddd„ƒ}| S )zû
    Key bindings for accepting auto suggestion text.

    (This has to come after the Vi bindings, because they also have an
    implementation for the "right arrow", but we really want the suggestion
    binding when a suggestion is available.)
    r	   Úboolc                  S  s.   t ƒ } | jjd uot| jjjƒdko| jjjS )Nr   )r   Úcurrent_bufferÚ
suggestionÚlenÚtextÚdocumentÚis_cursor_at_the_end)Úapp© r   ú£/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/bindings/auto_suggest.pyÚsuggestion_available    s   ÿýz8load_auto_suggest_bindings.<locals>.suggestion_availablezc-f)Úfilterzc-eÚrightÚeventÚEÚNonec                 S  s$   | j }|j}|r| |j¡ dS dS )z$
        Accept suggestion.
        N)r   r   Úinsert_textr   )r   Úbr   r   r   r   Ú_accept)   s
   ÿz+load_auto_suggest_bindings.<locals>._acceptÚescapeÚfc                 S  s>   | j }|j}|rt d|j¡}| tdd„ |D ƒƒ¡ dS dS )z*
        Fill partial suggestion.
        z([^\s/]+(?:\s+|/))c                 s  s   � | ]}|r|V  qd S )Nr   )Ú.0Úxr   r   r   Ú	<genexpr>@   s   € z<load_auto_suggest_bindings.<locals>._fill.<locals>.<genexpr>N)r   r   ÚreÚsplitr   r   Únext)r   r   r   Útr   r   r   Ú_fill6   s   þz)load_auto_suggest_bindings.<locals>._fillN)r	   r
   )r   r   r	   r   )r   Úaddr   r   )Úkey_bindingsÚhandler   r   r&   r   r   r   r      s   



)r	   r   )Ú__doc__Ú
__future__r   r"   Ú"prompt_toolkit.application.currentr   Úprompt_toolkit.filtersr   r   Ú'prompt_toolkit.key_binding.key_bindingsr   Ú(prompt_toolkit.key_binding.key_processorr   Ú__all__r   r   r   r   r   r   Ú<module>   s    ÿ