a
    åze  ã                   @   sB   d dl Z d dlZG dd„ dƒZedkr>d dlmZ eddd dS )	é    Nc                   @   s<   e Zd Zejej d Zdd„ Zdd„ Zdd„ Z	dd	„ Z
d
S )Ú
AutoExpandÚ_c                 C   s   |j | _ | j j| _d | _d S )N)ÚtextÚbellÚstate)ÚselfZeditwin© r   ú(/usr/lib/python3.9/idlelib/autoexpand.pyÚ__init__   s    
zAutoExpand.__init__c           
      C   sè   | j  d¡}| j  dd¡}| js.|  ¡ }d}n*| j\}}}}||ksL||krX|  ¡ }d}|sh|  ¡  dS |  ¡ }| j  dt|ƒ d¡ || }	|d t|ƒ }|dkr®|  ¡  | j  	d|	¡ | j  d¡}| j  dd¡}||||f| _dS )NÚinsertúinsert linestartzinsert lineendr   Úbreakzinsert - %d charsé   )
r   ÚindexÚgetr   Úgetwordsr   ÚgetprevwordÚdeleteÚlenr   )
r   ÚeventZ	curinsertZcurlineÚwordsr   r   ÚlineÚwordZnewwordr   r   r	   Úexpand_word_event   s.    zAutoExpand.expand_word_eventc           	      C   sÒ   |   ¡ }|sg S | j dd¡}t d| d |¡}~| j dd¡}t d| d |¡}~|sd|sdg S g }i }| ¡  |D ]"}| |¡rˆqx| |¡ |||< qx|D ]"}| |¡r°q | |¡ |||< q | |¡ |S )Nz1.0zinsert wordstartz\bz\w+\bzinsert wordendÚend)r   r   r   ÚreÚfindallÚreverseÚappend)	r   r   ÚbeforeZwbeforeZafterZwafterr   ÚdictÚwr   r   r	   r   6   s4    






zAutoExpand.getwordsc                 C   sF   | j  dd¡}t|ƒ}|dkr:||d  | jv r:|d }q||d … S )Nr   r   r   r   )r   r   r   Ú	wordchars)r   r   Úir   r   r	   r   U   s
    
zAutoExpand.getprevwordN)Ú__name__Ú
__module__Ú__qualname__ÚstringÚascii_lettersÚdigitsr"   r
   r   r   r   r   r   r   r	   r      s
   r   Ú__main__)Úmainz!idlelib.idle_test.test_autoexpandé   )Ú	verbosity)r   r'   r   r$   Zunittestr+   r   r   r   r	   Ú<module>   s
   K