a
     ³Šan  ã                   @   s8   d Z ddlmZ ddlmZ dd„ ZG dd„ deƒZdS )	z7This module contains the close quotes editor extension.é    )ÚQTextCursor)ÚEditorExtensionc                 C   sD   |   dd¡} |   dd¡} |  d¡d r*dS |  d¡d r<dS dS dS )a  Return whether a string has open quotes.

    This simply counts whether the number of quote characters of either
    type in the string is odd.

    Take from the IPython project (in IPython/core/completer.py in v0.13)
    Spyder team: Add some changes to deal with escaped quotes

    - Copyright (C) 2008-2011 IPython Development Team
    - Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
    - Copyright (C) 2001 Python Software Foundation, www.python.org

    Distributed under the terms of the BSD License.
    z\'Ú z\"ú"é   ú'N)ÚreplaceÚcount)Útext© r   úKlib/python3.9/site-packages/spyder/plugins/editor/extensions/closequotes.pyÚunmatched_quotes_in_line   s    r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCloseQuotesExtensionz9Editor Extension for insert closing quotes automatically.c                 C   s*   |r| j j | j¡ n| j j | j¡ dS )z*Connect/disconnect sig_key_pressed signal.N)ÚeditorZsig_key_pressedZconnectÚ_on_key_pressedZ
disconnect)ÚselfÚstater   r   r   Úon_state_changed-   s    z%CloseQuotesExtension.on_state_changedc                 C   sN   |  ¡ rd S | ¡ }|dv rJ| jrJ| jj ¡  |  |¡ | j ¡  | ¡  d S )N)r   r   )	Z
isAcceptedr
   Zenabledr   Zcompletion_widgetZhideÚ_autoinsert_quotesZdocument_did_changeZaccept)r   ZeventÚcharr   r   r   r   4   s    

z$CloseQuotesExtension._on_key_pressedc           	      C   s"  | j  dd¡}| j  dd¡}| j  ¡ }| j  dd¡dd… }| j  dd¡dd… }| j  dd¡ ¡ }| j  ¡ rÄ| j  ¡ }| j  d ||¡¡ | t	j
t	jd¡ | t	j
t	jt|ƒ¡ | j  |¡ nZ| j  ¡ rÞ| j  |¡ n@t|ƒd	krt|ƒ|ks|d	 d
vr| j  |¡ nt|ƒr>|d| ks>| j  |¡ nà| j  ¡ |krv| t	jt	jd¡ | ¡  | j  |¡ n¨|d| krÆ| j  d| ¡ | j  ¡ }| t	jt	jd¡ | ¡  | j  |¡ nX|d| krì| j  |¡ | j  ¡  n2| j  d| ¡ | j  ¡ }| t	j¡ | j  |¡ dS )zAControl how to automatically insert quotes in various situations.ZsolZeolÚcursoréýÿÿÿNéþÿÿÿz	{0}{1}{0}é   r   )ú,ú:ú;ú)ú]Ú}é   r   )r   Zget_textZ
textCursorÚstripZhas_selected_textZget_selected_textZinsert_textÚformatZmovePositionr   ZLeftZ
MoveAnchorZ
KeepAnchorÚlenZsetTextCursorZ
in_commentr   Z	next_charZNextCharacterZclearSelectionZPreviousCharacterZdelayed_popup_docstring)	r   r   Z	line_textZline_to_cursorr   Z
last_threeZlast_twoZtrailing_textr
   r   r   r   r   B   s^    


ÿ

ÿ
þ

ÿÿ
ÿ
z'CloseQuotesExtension._autoinsert_quotesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   *   s   r   N)r'   Z
qtpy.QtGuir   Zspyder.api.editorextensionr   r   r   r   r   r   r   Ú<module>   s   