B
    v9a  ã               @   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.7/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Úinsertzinsert linestartzinsert lineendr   Úbreakzinsert - %d charsé   )
r   ÚindexÚgetr   Úgetwordsr   ÚgetprevwordÚdeleteÚlenr   )
r   Z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 }| ¡  x*|D ]"}| |¡rŠqz| |¡ |||< qzW x*|D ]"}| |¡r¶q¦| |¡ |||< q¦W | |¡ |S )Nz1.0zinsert wordstartz\bz\w+\bzinsert wordendÚend)r   r   r   ÚreÚfindallÚreverseÚappend)	r   r   ZbeforeZwbeforeZafterZwafterr   ÚdictÚwr   r   r	   r   6   s4    






zAutoExpand.getwordsc             C   sJ   | j  dd¡}t|ƒ}x&|dkr<||d  | jkr<|d }qW ||d … S )Nzinsert linestartr   r   r   )r   r   r   Ú	wordchars)r   r   Úir   r   r	   r   U   s
    zAutoExpand.getprevwordN)Ú__name__Ú
__module__Ú__qualname__ÚstringZ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