
    Je	                     D    d Z ddlZddlmZ ddlmZ d Z G d de      Zy)z7This module contains the close quotes editor extension.    N)QTextCursor)EditorExtensionc                     t        j                  dd|       } t        j                  dd|       } | j                  d      dz  ry| j                  d      dz  ryy)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
(?<!\\)\\""   ')resubcount)texts    N/usr/lib/python3/dist-packages/spyder/plugins/editor/extensions/closequotes.pyunmatched_quotes_in_liner      sS    $ 66-T*D66-T*D zz#	C1	    c                   "    e Zd ZdZd Zd Zd Zy)CloseQuotesExtensionz9Editor Extension for insert closing quotes automatically.c                     |r0| j                   j                  j                  | j                         y| j                   j                  j	                  | j                         y)z*Connect/disconnect sig_key_pressed signal.N)editorsig_key_pressedconnect_on_key_pressed
disconnect)selfstates     r   on_state_changedz%CloseQuotesExtension.on_state_changed4   sA    KK''//0D0DEKK''2243G3GHr   c                     |j                         ry |j                         }|dv rS| j                  rF| j                  j                  j                          | j                  |       |j                          y y y )N)r   r	   )
isAcceptedr   enabledr   completion_widgethide_autoinsert_quotesaccept)r   eventchars      r   r   z$CloseQuotesExtension._on_key_pressed;   sa    
 zz|;4<<KK))..0##D)LLN $0r   c                 
   | j                   j                  dd      }| j                   j                  dd      }| j                   j                         }| j                   j                  dd      dd }| j                   j                  dd      dd }| j                   j                  dd      j                         }| j                   j	                         r| j                   j                         }| j                   j                  dj                  ||             |j                  t        j                  t        j                  d       |j                  t        j                  t        j                  t        |             | j                   j                  |       y| j                   j                         r| j                   j                  |       yt        |      d	kD  r1t!        |      |k(  s#|d	   d
vr| j                   j                  |       yt!        |      r$|d|z  k(  s| j                   j                  |       y| j                   j#                         |k(  r[|j                  t        j$                  t        j                  d       |j'                          | j                   j                  |       y|d|z  k(  r| j                   j                  d|z         | j                   j                         }|j                  t        j(                  t        j                  d       |j'                          | j                   j                  |       y|d|z  k(  r6| j                   j                  |       | j                   j+                          y| j                   j                  d|z         | j                   j                         }|j                  t        j(                         | j                   j                  |       y)zAControl how to automatically insert quotes in various situations.soleolcursorNz	{0}{1}{0}   r   ),:;)]}   r   )r   get_text
textCursorstriphas_selected_textget_selected_textinsert_textformatmovePositionr   Left
MoveAnchor
KeepAnchorlensetTextCursor
in_commentr   	next_charNextCharacterclearSelectionPreviousCharacterdelayed_popup_docstring)	r   r$   	line_textline_to_cursorr(   
last_threelast_twotrailing_textr   s	            r   r!   z'CloseQuotesExtension._autoinsert_quotesH   s   KK((6	--eX>'')[[))%:23?
;;''x8=,,Xu=CCE;;((*;;002DKK##K$6$6tT$BC 0 0+2H2H!L 0 0+2H2H #D	+KK%%f-[[##%KK##D)- 1$,^<D!!$(FFKK##D)&y11T6)KK##D)[[""$, 9 9 + 6 6;!!#KK%%f-1T6!KK##AdF+[[++-F = = + 6 6;!!#KK%%f- 4KK##D)KK//1 KK##AdF+[[++-F = =>KK%%f-r   N)__name__
__module____qualname____doc__r   r   r!    r   r   r   r   1   s    CI2.r   r   )rN   r
   
qtpy.QtGuir   spyder.api.editorextensionr   r   r   rO   r   r   <module>rR      s*    > 	 # 7>I.? I.r   