U
    Z¨+d¡  ã                   @  sV   d dl mZ d dlmZmZ d dlmZ ddlmZm	Z	m
Z
 dgZG dd„ de	ƒZdS )	é    )Úannotations)ÚIterableÚSet)ÚDocumenté   )ÚCompleteEventÚ	CompleterÚ
CompletionÚDeduplicateCompleterc                   @  s2   e Zd ZdZdddœdd„Zddd	d
œdd„ZdS )r
   zè
    Wrapper around a completer that removes duplicates. Only the first unique
    completions are kept.

    Completions are considered to be a duplicate if they result in the same
    document text when they would be applied.
    r   ÚNone)Ú	completerÚreturnc                 C  s
   || _ d S ©N)r   )Úselfr   © r   úI/tmp/pip-unpacked-wheel-blk8czbf/prompt_toolkit/completion/deduplicate.pyÚ__init__   s    zDeduplicateCompleter.__init__r   r   zIterable[Completion])ÚdocumentÚcomplete_eventr   c                 c  sp   t ƒ }| j ||¡D ]V}|jd |j|j … |j |j|jd …  }||jkrPq||krZq| |¡ |V  qd S r   )Úsetr   Úget_completionsÚtextZcursor_positionZstart_positionÚadd)r   r   r   Zfound_so_farÚ
completionZtext_if_appliedr   r   r   r      s    ÿþÿ

z$DeduplicateCompleter.get_completionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r
      s   N)Ú
__future__r   Útypingr   r   Zprompt_toolkit.documentr   Úbaser   r   r	   Ú__all__r
   r   r   r   r   Ú<module>   s
   