
    G@d                        d Z ddlZddlmZ ddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZmZmZmZ ddlmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddl m!Z!m"Z" ddl m#Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* g dZ+ G d de,          Z- G d de,          Z. G d de,          Z/ G d de,          Z0 G d de,          Z1 G d de1          Z2dS )zMix-in classes

These classes were created to be able to provide Spyder's regular text and
console widget features to an independent widget based on QTextEdit for the
IPython console plugin.
    N)parse)
QT_VERSION)QPointQRegularExpressionQtQUrl)QDesktopServicesQTextCursorQTextDocument)QApplication)getargspecfromtextgetobjgetsignaturefromtext)CONF)to_text_string)encoding
sourcecode)syntaxhighlighters)get_error_match)QStylePalette)ArrayBuilderDialog)

r   r      u        c                      e Zd Zej        Zej        Zej        Zej        Z	dZ
dZdZdZdZdZdZdZdZ e            Zd Zd	 Zd
 ZdRdZd Zd Zddddddedddf
dZdeeee
fdZddee
fdZdde
eedfdZddddedddeeddddfdZeeddfdZ d Z!dSdZ"dRdZ#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d  Z+dSd!Z,d" Z-d# Z.d$ Z/dTd&Z0d' Z1d( Z2d) Z3dTd*Z4d+ Z5dUd.Z6dUd/Z7d0 Z8d1 Z9d2 Z:dVd3Z;dTd4Z<dVd5Z=d6 Z>d7 Z?d8 Z@	 	 dWd9ZA	 	 dWd:ZBd; ZCd< ZDd= ZEd> ZFd? ZGd@ ZHdA ZIdB ZJdSdCZKdSdDZLdE ZMdSdFZNdG ZOdSdHZPdI ZQ	 	 dXdJZRdK ZS	 	 dYdMZTdZdNZUdO ZVdP ZWdQ ZXdS )[BaseEditMixinpython
   <   4      U   Nc                 "    d | _         d| _        d S )NiX  )	eol_charscalltip_sizeselfs    5lib/python3.11/site-packages/spyder/widgets/mixins.py__init__zBaseEditMixin.__init__P   s        c                     dS )zReturn line number area widthr    r-   s    r/   get_linenumberarea_widthz&BaseEditMixin.get_linenumberarea_widthU   s	     qr1   c                     |S )z
        Add offset to a point, to take into account the Editor panels.

        This is reimplemented in CodeEditor, in other widgets it returns
        the same point.
        r3   )r.   points     r/   calculate_real_positionz%BaseEditMixin.calculate_real_positionZ   s	     r1   c                    |                                  }|u|                                                                 dz  dz   }t          |                                |z
            }t          |                                |z
            }n|pd}|dz
  }t          |                                                     |                    }t          |                     |          	                                          }nN| 
                    d          \  }}t          |          }t          ||                                dz  z
            }t          j        dk    r+t          |                                dz  dz  d	z             }	net          j        d
k    r+t          |                                dz  dz            dz   }	n*t          |                                dz  dz            dz   }	|                     t#          ||                    }
|                     |
          }
|
                    |
                                |	z              |
S )z
        Calculate a global point position `QPoint(x, y)`, for a given
        line, local cursor position, or local point.
        N         cursordarwing333333?g\(\?g      @ntg?   )fontdocumentdocumentMarginintxyr
   findBlockByNumber
cursorRecttopget_coordinates	pointSizesysplatformosnamemapToGlobalr   r7   setY)r.   at_lineat_pointr@   margincxcyliner<   deltar6   s              r/   _calculate_positionz!BaseEditMixin._calculate_positiond   s   
 yy{{mmoo4466:a?FXZZ\\F*++BXZZ\\F*++BB BQ;D !B!B4!H!HIIFT__V,,002233BB ))(33FBRBR$..**Q..//B <8##))D0T9C?@@EEW__))D0T9::Q>EE))D0T9::Q>E   B00,,U33

57799u$%%%r1   c                 N   t          |          | j        v rdS | j                            t          |                     t          j        }t          j        }|j        j        }|                    |           d	                    |||          }|
                    |           dS )z4Update the background stylesheet to make it lighter.Nzs
            {0}#{0} {{
                background-color:{1};
                border: 1px solid {2};
            }})id_styled_widgetsaddr   COLOR_BACKGROUND_4COLOR_TEXT_4	__class____name__setObjectNameformatsetStyleSheet)r.   widget
backgroundborderrN   csss         r/   _update_stylesheetz BaseEditMixin._update_stylesheet   s     f::---F  F,,,"5
+(T""" &z622	 	
 	S!!!!!r1   c                     t          j        dd          }|r&t          j        dk    r|                    dd          }|S )zT
        Queries the editor's config to get the current "Inspect" shortcut.
        	shortcutszeditor/inspect current objectr=   CtrlCmd)r   getrK   rL   replace)r.   values     r/   _get_inspect_shortcutz#BaseEditMixin._get_inspect_shortcut   sC     &EFF 	5|x''fe44r1   Fc                 L   d}|                                  }|                                }|                                }|dk    r|dz
  n|}| j        }d}|r%||                    ||||          z  }|s|r|dz  }|r1|                    d          }||                    ||||          z  }|,|                                r|                                d	k    rd
}n|                                }|
s|                    dd                              dd                              dd                              dd                              dd                              dd                              dd                              dd                              dd                              dd                              dd                               d!d                              dd                              d"d!                                          }g }|D ]N}t          j	        ||#          }d$ |D             }d!
                    |          }|                    |           Od!
                    |          }|                    d          }|                                }t          |          d%k    r$|d%                                         s
|dd         }nd& |                    d!          D             }|rIt          |          |k    r!d!
                    |d|                   d'z   }nd!
                    |          }|                    d!d(          }|	r|rd(|z   }||                    ||||          z  }d}|rO|rd)                    ||*          }n5|                                 }|rd+t          j         d,t          j         d-}d}|r>|r<|r/|d.t          j         d/                    ||0          |z   d1z   z  }n|d2|z   d3z   z  }|S )4ay  
        Create HTML template for calltips and tooltips.

        This will display title and text as separate sections and add `...`

        ----------------------------------------
        | `title` (with `title_color`)         |
        ----------------------------------------
        | `signature`                          |
        |                                      |
        | `text` (ellided to `max_lines`)      |
        |                                      |
        ----------------------------------------
        | Link or shortcut with `inspect_word` |
        ----------------------------------------
        z
            <div style='font-family: "{font_family}";
                        font-size: {size}pt;
                        color: {color}'>
                {main_text}
            </div>
        	   r:    )font_familysizecolor	main_textz<hr>r   Nz<no docstring>z!<i>No documentation available</i>     z

z<!DOUBLE_ENTER!>z.
z.<!SINGLE_ENTER!>z
-z<!SINGLE_ENTER!>-z-
z-<!SINGLE_ENTER!>z
=z<!SINGLE_ENTER!>=z=
z=<!SINGLE_ENTER!>z
*z<!SINGLE_ENTER!>*z*
z*<!SINGLE_ENTER!>z
 z<!SINGLE_ENTER!> z 
z <!SINGLE_ENTER!>r   z<!SINGLE_ENTER!>)widthc                 :    g | ]}|                                 |S r3   strip.0ls     r/   
<listcomp>z.BaseEditMixin._format_text.<locals>.<listcomp>   s%     G G GqQWWYY G G G Gr1   r   c                 :    g | ]}|                                 |S r3   r|   r~   s     r/   r   z.BaseEditMixin._format_text.<locals>.<listcomp>  s%    >>>1AGGII>Q>>>r1   z ...<br>z}<span style="font-family: '{font_family}';font-size:{font_size}pt;">Click anywhere in this tooltip for additional help</span>)	font_sizert   zbackground-color:z;color:z;font-size:11px;z*<hr><div align="left"><span style="color: zI;text-decoration:none;font-family:"{font_family}";font-size:{size}pt;><i>)rt   ru   z</i></span></div>zF<hr><div align="left"><span style="color:white;text-decoration:none;">z</span></div>)r@   familyrJ   _DEFAULT_TEXT_COLORrb   r}   rn   
splitlinestextwrapwrapjoinappendlensplitrp   r   r]   COLOR_TEXT_1COLOR_ACCENT_4)r.   title	signaturetextinspect_wordtitle_color	max_lines	max_widthdisplay_linktext_new_linewith_html_formatBASE_TEMPLATEr@   rt   
title_size	text_size
text_colortemplate
paragraphsnew_paragraphs	paragraphnew_paragraphlines	help_textshortcut
base_styles                             r/   _format_textzBaseEditMixin._format_text   s   ( yy{{kkmm^^%%
&01nnJNN*	-
 		#,,'!	 -   H  #y #F" 	!//I,,' #	 -   H L

L

 0006DD::<<D )	? "77D11"76+=>>"75*=>>"75*=>>"75*=>>"75*=>>"75*=>>"75*=>>"75*=>>"75*=>>"75*=>>"74--"7#5v>>"7#5t<<ZZ\\   N' 5 5	 (iy I I I !H GM G G G !%		- 8 8 %%m4444 >22J#))&11J))++E 5zzA~~eAhnn&6&6~abb	>>

4 0 0>>>E  	(5zzI%%yyz	z!233f<yy''||D&)) 	!Y 	!D=DM((#	 ) 
 
 	
 	 	# # %f"+$/ %  	 	  5577 #*M,L * *!.!;* * * 
 !#I  	 	 +8+G  
 v+#,  . .!" %88 8  ## &55 r1   c                    t          | d|                                          }dd                    | j                  dz   }fd}t	          |t
                    s|g}g }	|D ]E}
d                    |
                                          }
|
                    dd          }
r}|d	k    rwg d
}g d}}||z   D ]_}||v r-d                    |          }|                    ||          }3|                    |d          }                    |d          `d|z   dz   }g }|
                    d          d         }dt          |          dz   z  }t          j        |
||          }|D ]}r|d	k    rt          j        |||          }|                    dd          }|                    dd          }|                    dd          }|r7|d	k    r1dD ].}|                    |          }|                    ||          }/|                    |           d                    |          }|                                 }|                                }|                                }r |d	k    r|                    |||          }n|}|	                    |           Gd                    |	          S )z
        Create HTML template for signature.

        This template will include indent after the method name, a highlight
        color for the active parameter and highlights for special chars.

        Special chars depend on the language.
        languagezi<span style='font-family:"{font_family}";font-size:{font_size}pt;color:{color}'><b>{parameter}</b></span>z<span style="color:{0};zfont-weight:bold">{char}</span>c                 ^    |                      d          }|                              }|S )z
            Handle substitution of active parameter template.

            This ensures the correct highlight of the active parameter.
            r   )grouprn   )matchobjmatchnewactive_parameter_template	parameters      r/   
handle_subz3BaseEditMixin._format_signature.<locals>.handle_subq  s/     NN1%%E--	+DEECJr1   ry   z( (r$   )|.^$*+)r   ){}[]z\{char})charrs   z[\*|\(|\[|\s](z)[,|\)|\]|\s|=]r   r:   )rz   subsequent_indentz&nbsp;z
span&nbsp;zspan z{}z{{}})r   r   ,r   z**r   )r   rt   rv   r   )getattrlowerrb   _CHAR_HIGHLIGHT_COLOR
isinstancelistr   r   rn   r   r   r   resubr   r@   rJ   r   )r.   
signaturesr   r   parameter_color
char_colorr   chars_templater   new_signaturesr   escape_regex_charsremove_regex_charsregex_parameter
regex_charescape_charpatternformatted_linesrN   indentrowsrowr   new_chartitle_templater@   r   rt   r   r   s     `                          @r/   _format_signaturezBaseEditMixin._format_signatureV  sk    4X66<<>> 	" &,,T-GHH 		 	 	 	 	 	 *d++ 	&$J# @	) @	)I!2!233I "))$44I  /X11 &D%C%C"%C%C%C""+"47I"I F FJ!%777&0&7&7Z&7&H&H*9*A*A*BM+O +O +:*A*A*BD+F +F$-$5$5j"$E$E		,>-. !O??3''*DCIIM*F=)39; ; ;D , , ;X!5!5&*c::Ckk#x00kk,88kk$// :H 4 4 : : :#1#8#8d#8#C#C!kk$99&&s++++#[[99N 99;;D((I++--K  'X11&--' +)'	 .   '!!%(((({{>***r1   c                    d}d}d}t          | d|                                          }|                    dd          }|                    dd          }|                    dd	          }d
 |                    d          D             }	d                    |	          }|dk    rd}d}|r|                    |          }n!|                    |          }
|d|
         }d}|r||z   g }|	D ]h}|                              rI|                              dk    r0|                              }fd|D             }d |D             }n|g}||z   }i|}	d}|	D ]}|                              r|dz  }|dk    }|dk    ot          |	          dk    }|r|st          |	          D ]\  }}|
                                dk    r n |dk    r|	d         }d}nBd                    |	d|                   }d                    |	|d                   }|dk    rd}|r|                     |||          }n|r|                    dz             }|dd         }|                    dd          }|                    dd          }|                    dd          }|                    dd          }|                    d          }d |D             }|                     |||          }d}nd}|}|||fS )z
        LSP hints might provide docstrings instead of signatures.

        This method will check for multiple signatures (dict, type etc...) and
        format the text accordingly.
        rs   Fr   \*r   r   z&#123;r   z&#125;c                     g | ]}d |v|	S )ufuncr3   )r   rV   s     r/   r   z=BaseEditMixin._check_signature_and_format.<locals>.<listcomp>  s,     ) ) )$4'' '''r1   r   r$   r   NTr:   c                     g | ]}|z   S r3   r3   )r   r   name_plus_chars     r/   r   z=BaseEditMixin._check_signature_and_format.<locals>.<listcomp>  s    #I#I#I1NQ$6#I#I#Ir1   c                 6    g | ]}|                                 S r3   r|   r~   s     r/   r   z=BaseEditMixin._check_signature_and_format.<locals>.<listcomp>  s     #@#@#@!AGGII#@#@#@r1   r   )r   r   r   r      ry   z\\*c                     g | ]}||S r3   r3   )r   sigs     r/   r   z=BaseEditMixin._check_signature_and_format.<locals>.<listcomp>  s    ;;;#s;#;;;r1   )r   r   rn   r   r   
startswithfindcountr   	enumerater}   r   )r.   signature_or_textr   r   r   r   open_func_charhas_signaturehas_multisignaturer   idx	all_linesrV   sublinesr   ir   
extra_textnew_signaturer   r   s                       @r/   _check_signature_and_formatz)BaseEditMixin._check_signature_and_format  s    "4X66<<>>-55eSAA .55c8DD-55c8DD) )"3"9"9$"?"? ) ) ) IIe,,x N!& % 1 < <\ J J',,^<<0#6 $ B!-!>	! 	5 	5D77 * $

> : :Q > >#'::n#=#=#I#I#I#I#I#I#I#@#@x#@#@#@$(6 )H 4II!! # #D~66 #
 !&
%*QY%A3u::>" &	+!3 &	+$U++  4::<<2%%E & Avv!!H	!

 IIeBQBi00	!YYuQRRy11
%%!%J  $ 6 6('' !7 ! !
   	+)11.28>2IK KI!!""I!))$44I!))&#66I!))%55I!))&$77I"..J;;;;;J 22%## 3  M
 JJ M*Jj,66r1   Tc           	      f   |                                  }|                                }d}	t          | d|                                          }|dk    r|r|                    d          d         }	d}
|r;|
                    |                                                              dd           d                    |                                          }|
|k    r|}d	}|rC|                    dd          }|                                r|                    |d
z   d	          }|                     |||	||          }|\  }}}	|                     ||	d||||          }| 	                    | j
                   | j
                            ||g            | j
                                         dS )z
        Show calltip.

        Calltips look like tooltips but will not disappear if mouse hovers
        them. They are useful for displaying signature information on methods
        and functions.
        Nr   r$   r   r   ry   r   r   rs   r   )r   r   r   F)r   r   r   r   r   r   r   )rX   r}   r   r   r   r   rn   r   r   rh   calltip_widgetshow_tipshow)r.   r   r   documentationr   r   r   r   r6   r   	check_doc	check_sigresr   r   s                  r/   show_calltipzBaseEditMixin.show_calltip*  s    ((**OO%%	4X66<<>>xI$??3//2L I J}224455==eSIII!2!233II%%)	 "  	L)11%==M   L - 5 5i$6F K K ..y)<H8@9B / D D -0)t\  #%' ! 
 
 	 3444 	$$UD"555  """""r1   c                     |                      ||          }|                     |||||||	|
||
  
        }|                     | j                   | j                            ||||           dS )zShow tooltip.)rQ   rR   )
r   r   r   r   r   r   r   r   r   r   )r<   completion_docN)rX   r   rh   tooltip_widgetr   )r.   r   r   r   r   r   rQ   rR   r   r   r   r<   r   r   r   r6   tiptexts                    r/   show_tooltipzBaseEditMixin.show_tooltipa  s     (( ) 
 

 ###%%-' $ 
 
 	 3444 	$$UGF4B 	% 	D 	D 	D 	D 	Dr1   c                 >   |                      |||          }|\  }	}
}|                     |          }|
g|                     |          }|                    t          j        t          j                   || _        |                     |	|
||d|||||
  
         dS dS )z'Show code hint and crop text as needed.)r   r   NT)
r   r   rR   r   r   r   r   r<   r   r   )	r   get_word_start_poscursorForPositionmovePositionr
   StartOfWord
MoveAnchor_last_hover_cursorr   )r.   r   r   rR   r   r   r   r   r   html_signaturer   _r6   r<   s                 r/   	show_hintzBaseEditMixin.show_hint  s    
 ..ty<H / J J(+%
A''11 !++H55F 7 + 68 8 8&,D#Z',<+/9(1&,9-;  = = = = = "!r1   c                 b    d| _         d| _        d| _        | j                                         dS )a&  
        Hide the tooltip widget.

        The tooltip widget is a special QLabel that looks like a tooltip,
        this method is here so it can be hidden as necessary. For example,
        when the user leaves the Linenumber area when hovering over lint
        warnings and errors.
        N)r  _last_hover_word_last_pointr   hider-   s    r/   hide_tooltipzBaseEditMixin.hide_tooltip  s7     #' $  """""r1   c                     d S Nr3   r.   r   s     r/   document_did_changez!BaseEditMixin.document_did_change  s    r1   c                     |)t          j        |          }|duo| j        du}|| _        n||| j        k    }|| _        |rJ|                                                     d           | j        | j                            |           dS dS dS )a7  
        Set widget end-of-line (EOL) characters.

        Parameters
        ----------
        text: str
            Text to detect EOL characters from.
        eol_chars: str
            EOL characters to set.

        Notes
        -----
        If `text` is passed, then `eol_chars` has no effect.
        NT)r   get_eol_charsr+   rA   setModifiedsig_eol_chars_changedemit)r.   r   r+   detected_eol_charsis_document_modifieds        r/   set_eol_charszBaseEditMixin.set_eol_chars  s     !+!9$!?!?"$.M4>3M ! 0DNN"#,#> &DN 	;MMOO''---)5*//	:::::	; 	;55r1   c                 6    | j         | j         S t          j        S )z/Return line separator based on current EOL mode)r+   rM   linesepr-   s    r/   get_line_separatorz BaseEditMixin.get_line_separator  s    >%>!:r1   c                     |                                  }|                                 }t          D ]}|                    ||          }|S )za
        Same as 'toPlainText', replacing '
' by correct end-of-line
        characters.
        )toPlainTextr  EOL_SYMBOLSrn   )r.   r   r  symbols       r/   get_text_with_eolzBaseEditMixin.get_text_with_eol  sO    
 !!))++! 	1 	1F<<00DDr1   c                    |                                  }|dk    rn|dk    r |                    t          j                   nt|dk    r |                    t          j                   nN|dk    r |                    t          j                   n(|dk    r |                    t          j                   n|S |                                S )zYGet offset in character for the given subject from the start of
           text edit arear<   soleoleofsof)
textCursorr  r
   StartOfBlock
EndOfBlockEndStartposition)r.   subjectr<   s      r/   get_positionzBaseEditMixin.get_position  s     ""h 89999 677770000 12222 N   r1   c                    |                      |          }|                                 }|                    |           |                     |                                          }|                                |                                fS r  )r0  r)  setPositionrG   centerrD   rE   )r.   r.  r<   r6   s       r/   rI   zBaseEditMixin.get_coordinates  sp    $$X..""8$$$''..00wwyy%''))##r1   c                 |   |                      |          }|                    t          j        t          j                   |                     |          }|                    t          j        t          j                   |                     |          }|                    |          }|                    |          S )zS
        Check if the mouse is within the rect of the cursor current word.
        )	r  r  r
   r  r  rG   	EndOfWordunitedcontains)r.   r6   r<   
start_rectend_rectbounding_rects         r/   _is_point_inside_word_rectz(BaseEditMixin._is_point_inside_word_rect  s     ''..K3[5KLLL__V,,
K1;3IJJJ??6**"))(33%%e,,,r1   c                    |                      |          }|                    t          j        t          j                   |                     |          }t          |                                dz   |                                          }|S )zV
        Find start position (lower bottom) of a word being hovered by mouse.
        r   )	r  r  r
   r  r  rG   r   leftrH   )r.   r.  r<   rectposs        r/   r  z BaseEditMixin.get_word_start_pos  sl     ''11K3[5KLLLv&&TYY[[1_dhhjj11
r1   c                     | j         S )z'Return the last (or active) hover word.r  r-   s    r/   get_last_hover_wordz!BaseEditMixin.get_last_hover_word      $$r1   c                     | j         S )z)Return the last (or active) hover cursor.)r  r-   s    r/   get_last_hover_cursorz#BaseEditMixin.get_last_hover_cursor  s    &&r1   c                 ~    ||                                  }|                                |                                fS )z{
        Return `cursor` (line, column) numbers.

        If no `cursor` is provided, use the current text cursor.
        )r)  blockNumbercolumnNumberr.   r<   s     r/   get_cursor_line_columnz$BaseEditMixin.get_cursor_line_column  s;     >__&&F!!##V%8%8%:%:::r1   c                 T    |                                                                  dz   S )zReturn cursor line numberr:   )r)  rG  r-   s    r/   get_cursor_line_numberz$BaseEditMixin.get_cursor_line_number$  s#      ,,..q00r1   c                 2   |                                                      |          }t          |          }|                    t          j                   |                    t          j        t          j        |dz              |                                S )z1Get position offset from (line, col) coordinates.r:   )n)rA   rF   r
   r  r*  Right
KeepAnchorr.  )r.   rV   colblockr<   s        r/   get_position_line_numberz&BaseEditMixin.get_position_line_number(  s    11$77U##K4555K-{/E!Ag 	 	' 	' 	'   r1   c                     |                      |          }|                                 }|                    |           |                     |           |                                  dS )zSet cursor positionN)r0  r)  r2  setTextCursorensureCursorVisible)r.   r.  r<   s      r/   set_cursor_positionz!BaseEditMixin.set_cursor_position1  sd    $$X..""8$$$6"""  """""r1   r   c                     |dk    rt           j        nt           j        }t          t	          |                    D ]"}|                     |t           j                   #dS )z/Move cursor to left or right (unit: characters)r   N)r
   rO  Leftrangeabs
moveCursorr  )r.   chars	direction_is       r/   move_cursorzBaseEditMixin.move_cursor9  s[    ).K%%8H	E

## 	? 	?BOOI{'=>>>>	? 	?r1   c                     |                                  }|                    t          j                   |                                S )z*Return True if cursor is on the first line)r)  r  r
   r*  atStartrI  s     r/   is_cursor_on_first_linez%BaseEditMixin.is_cursor_on_first_line?  s8    ""K4555~~r1   c                     |                                  }|                    t          j                   |                                S )z)Return True if cursor is on the last line)r)  r  r
   r+  atEndrI  s     r/   is_cursor_on_last_linez$BaseEditMixin.is_cursor_on_last_lineE  s6    ""K2333||~~r1   c                 N    |                                                                  S )z/Return True if cursor is at the end of the text)r)  re  r-   s    r/   is_cursor_at_endzBaseEditMixin.is_cursor_at_endK  s      &&(((r1   c                 &   |                      |          |z   }|                                 }|                    t          j                   ||                                k     r-|                    |           |                                 |k     S dS )z*Return True if cursor is before *position*N)r0  r)  r  r
   r,  r.  r2  )r.   r.  char_offsetr<   s       r/   is_cursor_beforezBaseEditMixin.is_cursor_beforeO  s    $$X..<""KO,,,foo''''x(((??$$v-- ('r1   c                 "   |dv sJ |dk    rR|dk    r"|                      t          j        |           d S |dk    r"|                      t          j        |           d S d S |dk    rR|dk    r"|                      t          j        |           d S |dk    r"|                      t          j        |           d S d S |dk    rP|dk    r"|                      t          j        |           d S |dk    r$|                      t          j        |           d S d S d S )	N)	characterwordrV   rm  r=  rightrn  rV   downup)r\  r
   PreviousCharacterNextCharacterPreviousWordNextWord	NextBlockPreviousBlock)r.   whatr^  	move_modes       r/   __move_cursor_anchorz"BaseEditMixin.__move_cursor_anchorX  s@   44444;F"" =yIIIIIg%% 99EEEEE &%V^^F"" 8)DDDDDg%% 4i@@@@@ &%V^^F"" 5yAAAAAd"" 99EEEEE	 ^ #"r1   rn  r=  c                 H    |                      ||t          j                   dS )zs
        Move cursor to next *what* ('word' or 'character')
        toward *direction* ('left' or 'right')
        N)"_BaseEditMixin__move_cursor_anchorr
   r  r.   rx  r^  s      r/   move_cursor_to_nextz!BaseEditMixin.move_cursor_to_nextj  %    
 	!!$	;3IJJJJJr1   c                 H    |                      ||t          j                   dS )zx
        Extend selection to next *what* ('word' or 'character')
        toward *direction* ('left' or 'right')
        N)r|  r
   rP  r}  s      r/   extend_selection_to_nextz&BaseEditMixin.extend_selection_to_nextr  r  r1   c                     |                      |          }|                      |          }|                                 }|                    |           |                    |t          j                   |S )zSelect text and return cursor.)r0  r)  r2  r
   rP  )r.   position_fromposition_tor<   s       r/   _select_textzBaseEditMixin._select_text{  si    ))-88''44""=)));(>???r1   c                 D   |                                                      |          }t          |          }|                    t          j                   |                    t          j        t          j                   t          |                                          S )z)Return text line at line number *line_nb*mode)	rA   rF   r
   r  r*  r+  rP  r   selectedText)r.   line_nbrR  r<   s       r/   get_text_linezBaseEditMixin.get_text_line  sz    11'::U##K4555K29OPPPf1133444r1   c                    |                                                      |          }|                                                      |          }t          |          }|                    t          j                   t          |          }|                    t          j                   |                                }|                    |t          j                   | 	                    |          S )z:Return text lines spanned from *start_line* to *end_line*.r  )
rA   rF   r
   r  r*  r+  r.  r2  rP  get_selected_text)r.   
start_lineend_linestart_block	end_blockstart_cursor
end_cursorend_positions           r/   get_text_regionzBaseEditMixin.get_text_region  s    mmoo77
CCMMOO55h??	";//!!+":;;; ++
 6777!**,,  K4J KKK%%l333r1   c                     |                      ||          }t          |                                          }|r|dk    p|dk    }|r.|r,|r*|d         t          v r|dd         }|r|d         t          v |S )ac  Returns text between *position_from* and *position_to*.

        Positions may be integers or 'sol', 'eol', 'sof', 'eof' or 'cursor'.

        Unless position_from='sof' and position_to='eof' any trailing newlines
        in the string are removed. This was added as a workaround for
        spyder-ide/spyder#1546 and later caused spyder-ide/spyder#14374.
        The behaviour can be overridden by setting the optional parameter
        *remove_newlines* to False.

        TODO: Evaluate if this is still a problem and if the workaround can
              be moved closer to where the problem occurs.
        r(  r'  N)r  r   r  r!  )r.   r  r  remove_newlinesr<   r   s         r/   get_textzBaseEditMixin.get_text  s     ""=+>>f113344 	M+u4Lu8LO 	!O 	! !48{22CRCy  !48{22r1   c                    |                      |          |z   }|                                 }|                    t          j                   ||                                k     r`|                    |           |                    t          j        t          j                   t          |
                                          S dS )z5Return character at *position* with the given offset.rs   )r0  r)  r  r
   r,  r.  r2  rO  rP  r   r  )r.   r.  offsetr<   s       r/   get_characterzBaseEditMixin.get_character  s    $$X..7""KO,,,foo''''x((( 1 + 68 8 8!&"5"5"7"78882r1   c                 
   |                                  sl|r!| j        | j                            |           |                                                     |           | j        | j                                         dS dS dS )zInsert text at cursor positionN)
isReadOnlysig_will_insert_textr  r)  
insertTextsig_text_was_inserted)r.   r   will_insert_texts      r/   insert_textzBaseEditMixin.insert_text  s       	2 5D$=$I)..t444OO((...)5*//11111	2 	2 65r1   c                 ~   |                      ||          }| j        3|                     |          \  }}| j                            ||           |                                 | j        | j                            |           |                    |           | j        | j                                         d S d S r  )r  sig_will_remove_selectionget_selection_start_endr  removeSelectedTextr  r  r  )r.   r  r  r   r<   startends          r/   replace_textzBaseEditMixin.replace_text  s    ""=+>>)555f==JE3*//s;;;!!###$0%**4000$%1&++----- 21r1   c                     |                      ||          }| j        3|                     |          \  }}| j                            ||           |                                 d S r  )r  r  r  r  r  )r.   r  r  r<   r  r  s         r/   remove_textzBaseEditMixin.remove_text  sh    ""=+>>)555f==JE3*//s;;;!!#####r1   c                 ~   |                                  }|                                }|                     d          }|                    t          j                   |                     |                                                                          rm|                    t          j                   |                                rn9|                     |                                                                          m|                                }|	                    |           |                     |                                                                          rm|                    t          j
                   |                                rn9|                     |                                                                          m|                                }|                     ||                                          }|}|r*|(||k    r"||v r|                    |          d         |z   }|S )a  
        Return current object under cursor.

        Get the text of the current word plus all the characters
        to the left until a space is found. Used to get text to inspect
        for Help of elements following dot notation for example
        np.linalg.norm
        T)help_reqNr   )r)  r.  get_current_wordr  r
   rr  r  r}   atBlockStartr2  rs  
atBlockEndr  r   )r.   r<   
cursor_poscurrent_wordcursor_pos_leftcursor_pos_rightcurrent_textcurrent_objects           r/   get_current_objectz BaseEditMixin.get_current_object  s    ""__&&
,,d,;; 	K9:::  !2!23399;; 	 =>>>""$$    !2!23399;; 	 !//++ 	:&&&  !2!23399;; 	 9:::  ""    !2!23399;; 	 "??,, }}-/ //4uww 	% 	HL4|++0L0L &&|44Q7,F  r1   c                 X                                      }|                                }|                                rJ|                    t	          |                                |                                g                     n fd} fd}|rj |t          j                  r |	                    t          j
                   n |t          j
                  r|	                    t          j                   n|sL |t          j
                  r6 |t          j                  rdS |	                    t          j                   nK |t          j                  rdS  |t          j
                  r|	                    t          j                   |                    t          j                   t          |                                          }|                                }	|r,t!          j        d|t           j                  }
|
sdS |
d         }|r|d||	z
           }||	fS )zd
        Return current word, i.e. word at cursor position, and the start
        position.
        c                                                      }|                    | t          j                   t	          |                                                                           S r  )r)  r  r
   rP  r   r  r}   )movecursr.   s     r/   is_spacez=BaseEditMixin.get_current_word_and_position.<locals>.is_space  sT    ((!!$(>???)$*;*;*=*=>>DDFFFFr1   c                 4                                    }|                    | t          j                   t	          |                                                                          }t          t          j	        d|t          j
                            dk    S )z7Check if a character is a non-letter including numbers.([^\d\W]\w*)r   )r)  r  r
   rP  r   r  r}   r   r   findallUNICODE)r  r  text_cursorr.   s      r/   is_special_characterzIBaseEditMixin.get_current_word_and_position.<locals>.is_special_character   s    ((!!$(>???,T->->-@-@AAGGIIJRZHHJ JMNO Or1   Nr  r   )r)  r.  hasSelectionr2  minselectionStartselectionEndr
   rr  r  rs  WordLeftselectWordUnderCursorr   r  r   r  r  )r.   
completionr  valid_python_variabler<   r  r  r  r   startposr   s   `          r/   get_current_word_and_positionz+BaseEditMixin.get_current_word_and_position  s]    ""__&&
   )	>
 sF$9$9$;$;$*$7$7$9$9$;  <  < = = = =G G G G G
O O O O O  >''(EFF G''(ABBBB))+*CDD G''(EFFF 	>8K566 >x =>> ''(<===8K9:: F(()BCC >''(<===k1222f113344((** ! 	 JbjAAE   tQx 	0.h../DX~r1   c                 J    |                      |||          }||d         S dS )z2Return current word, i.e. word at cursor position.)r  r  r  Nr   )r  )r.   r  r  r  rets        r/   r  zBaseEditMixin.get_current_wordK  s>     00!"7 1 
 
 ?q6M ?r1   c                     | j         S )z7Return the last hover word that requested a hover hint.rA  r-   s    r/   get_hover_wordzBaseEditMixin.get_hover_wordW  rC  r1   c                     |                                  }|                    t          j                   t	          |                                          S )zReturn current line's text.)r)  r  r
   BlockUnderCursorr   r  rI  s     r/   get_current_linezBaseEditMixin.get_current_line[  s@    ""k2333f1133444r1   c                 8    |                      | j        d          S )z"Return text from prompt to cursor.r<   )r  current_prompt_posr-   s    r/   get_current_line_to_cursorz(BaseEditMixin.get_current_line_to_cursora  s    }}T4h???r1   c                 Z    |                      |          }|                                dz   S )z-Return line number at *coordinates* (QPoint).r:   )r  rG  r.   coordinatesr<   s      r/   get_line_number_atz BaseEditMixin.get_line_number_ate  s,    ''44!!##a''r1   c                     |                      |          }|                    t          j                   t	          |                                                              dd          S )z&Return line at *coordinates* (QPoint).r!   rs   )r  r  r
   r  r   r  rn   r  s      r/   get_line_atzBaseEditMixin.get_line_atj  sT    ''44k2333f113344<<YKKKr1   c                     |                      |          }|                    t          j                   |                     |          r"t          |                                          }nd}|S )z&Return word at *coordinates* (QPoint).rs   )r  r  r
   r  r;  r   r  )r.   r  r<   rn  s       r/   get_word_atzBaseEditMixin.get_word_atp  se    ''44k1222**;77 	!&"5"5"7"788DDDr1   c                     |                     dd| j        z            }t          |          t          |                                          z
  S )zGet indentation for given line.	ry   )rn   tab_stop_width_spacesr   lstripr  s     r/   get_line_indentationz"BaseEditMixin.get_line_indentation{  s>    ||D#d&@"@AA4yyT[[]]++++r1   c                     t          |                                                     |                                                    }|                     |          S )z+Return line indentation (character number).)r   rA   rF   r   r  )r.   block_nbr   s      r/   get_block_indentationz#BaseEditMixin.get_block_indentation  sE    dmmoo??IINNPPQQ((...r1   c                    ||                                  }|                                |                                }}|                                                     |          }|                                                     |          }t          |                                |                                g          S )z(Return selection bounds (block numbers).)r)  r  r  rA   	findBlocksortedrG  )r.   r<   r  r  block_start	block_ends         r/   get_selection_boundsz"BaseEditMixin.get_selection_bounds  s    >__&&F**,,f.A.A.C.Csmmoo//66MMOO--c22	{..00)2G2G2I2IJKKKr1   c                 j   ||                                  }|                                |                                }}t          |          }|                    |           |                     |          }t          |          }|                    |           |                     |          }||fS )z8Return selection start and end (line, column) positions.)r)  r  r  r
   r2  rJ  )r.   r<   r  r  r  start_positionr  r  s           r/   r  z%BaseEditMixin.get_selection_start_end  s    >__&&F**,,f.A.A.C.Cs"6**  '''44\BB ((
s###22:>>|++r1   c                     t          t          |                                                                                     S )z&Returns True if some text is selected.)boolr   r)  r  r-   s    r/   has_selected_textzBaseEditMixin.has_selected_text  s.    N4??#4#4#A#A#C#CDDEEEr1   c                     ||                                  }t          |                                                              d|                                           S )u   
        Return text selected by current text cursor, converted in unicode.

        Replace the unicode line separator character   by
        the line separator characters returned by get_line_separator
        Nr!   )r)  r   r  rn   r  rI  s     r/   r  zBaseEditMixin.get_selected_text  sX     >__&&Ff113344<<Y595L5L5N5NP P 	Pr1   c                    |                                                                   t          t                    t          d          k     s t          j        dk    st          j        dk    rR|                                  }|                    |	                                           | 
                    |           dS dS )zDelete selected text.z5.15r>   r=   N)r)  r  r   r   rM   rN   rK   rL   r2  r.  rU  rI  s     r/   remove_selected_textz"BaseEditMixin.remove_selected_text  s    ,,... *f--w$#,(":":__&&Fv00111v&&&&&	 #;":r1   c                    |                                  }|                                 |!t          |                                          }| j        3|                     |          \  }}| j                            ||           |                                 |=t          j	        t          |          t          |          t          |                    }| j
        | j
                            |           |                    |           | j        | j                                         |                                 dS )zReplace selected text by *text*.

        If *pattern* is not None, replacing selected text using regular
        expression text substitution.N)r)  beginEditBlockr   r  r  r  r  r  r   r   r  r  r  endEditBlock)r.   r   r   r<   seltxtr  r  s          r/   rn   zBaseEditMixin.replace  s1   
 ""#F$7$7$9$9::F)555f==JE3*//s;;;!!###6.11(..v0F0FH HD$0%**4000$%1&++---r1   c                 8   t          |                                          }t          |                                           }	 t          j        |          }n# t
          j        $ r Y dS w xY w|t          j        z  rmt          |
                                |                                g          }|d|         }d |                    |d|          D             }|r	|d         }	nMdS t          |
                                |                                g          }|                    ||          }	|	rbt          j        |	          \  }
}|                                 }|                    |
           |                    |t&          j                   |S dS )zbReimplement QTextDocument's find method.

        Add support for *multiline* regular expressions.Nc                     g | ]}|S r3   r3   )r   _ms     r/   r   z8BaseEditMixin.find_multiline_pattern.<locals>.<listcomp>  s    EEEbrEEEr1   r   r  )r   r   r   r   compilesre_constantserrorr   FindBackwardr  r  r  finditermaxsearchshget_spanr)  r2  r
   rP  )r.   regexpr<   findflagr   r   regobjr  matchesr   pos1pos2fcursors                r/   find_multiline_patternz$BaseEditMixin.find_multiline_pattern  s    !!1!122d..0011	Z((FF" 	 	 	FF	m00 	0&--//1F1F1H1HIJJF=DEEFOOD!V$D$DEEEG  &--//1F1F1H1HIJJFMM$//E 	U++JD$oo''G%%%k&<===N	 	s   A A,+A,c                    |                                  }t          j                    }t          | dd          r|                                 }	nd}	|s|t          j        z  }|r|t          j        z  }t          j        g}
|r|
t          j	        t          j
        gz  }
|rt          |                                          rKt          |                                |                                g          }|                    |           n0|                    t          j                   n|
t          j        gz  }
|rt          |          }n!t)          j        t          |                    }t-          |rd                    |          n|          }|r|                    t,          j                   |
D ]}|                    |           |rd|v r|                     |||          }n)|                                                     |||          }|^|                                sJ|                     |           |	0|                                 }|	|k    r|}	|                                   dS dS )z
Find text.get_visible_block_numbersFNz\b{}\bz\nT) r)  r   FindFlagr   r  r  FindCaseSensitivelyr
   NoMoveru  r-  r   r  r  r  r  r2  r  rt  r,  r   escaper   rb   setPatternOptionsCaseInsensitiveOptionr  rA   r   isNullrU  centerCursor)r.   r   changedforwardcasern  r  r<   r  current_visible_regionmovesnew_positionr   r  found_cursorfound_visible_regions                   r/   	find_textzBaseEditMixin.find_text  s    "" )++ 44e<< 	*%)%C%C%E%E""%)" 	=-"<<H 	D-"CCH#$ 
	'k*K,=>>E B!&"5"5"7"788 B#&(=(=(?(?(.(;(;(=(=(? $@ $@L&&|4444''(@AAAko&&E 	3!$''DD9^D1122D$ &*[%7%7%=%=%=%)+ + 	P%%&8&NOOO 	 	D%%% O%4--#::7F;C E  E
  $}}33GVXNN'0C0C0E0E'""<000 *5+/+I+I+K+K(-1EEE1E.))+++ttur1   c                     dS )z>Needs to be overloaded in the codeeditor where it will be TrueFr3   r-   s    r/   	is_editorzBaseEditMixin.is_editor3  s    ur1   rs   c                    t          |          }|sdS |st          j        |          }|s!t          |                                           }|rd                    |          }	 |rt          j        nt          j        t          j        z  }t          j        ||          }n# t          j	        $ r Y dS w xY wd}|
                    |          D ]}	|dz  }|S )z0Get the number of matches for the searched text.r   z\b{pattern}\b)r   )flagsNr:   )r   r   r  r   rb   	MULTILINE
IGNORECASEr  r  r   r  )
r.   r   source_textr  r  rn  re_flagsr	  number_matchesr   s
             r/   get_number_matchesz BaseEditMixin.get_number_matches7  s    !)) 	1 	)i((G 	=()9)9););<<K 	?&--g->>G	'+Mr||1MHZx888FF" 	 	 	44	 __[11 	  	 EaNNs   &=B$ $B76B7c                     |                                                                  }|                     d|          }|                     |||||          }|S )z.Get number of the match for the searched text.r(  )r  r  )r(  r  r  rn  )r)  r.  r  r+  )r.   r   r  r  rn  r.  r(  match_numbers           r/   get_match_numberzBaseEditMixin.get_match_numberR  sa    ??$$--//mm%XmNN..w;F4848 / : : r1   c                 0    |                      d           dS )z Enter array builder inline mode.TN_enter_arrayr-   s    r/   enter_array_inlinez BaseEditMixin.enter_array_inline]  s    $r1   c                 0    |                      d           dS )zEnter array builder table mode.FNr0  r-   s    r/   enter_array_tablezBaseEditMixin.enter_array_tablea  s    %     r1   c                 V   |                      d          |                      d          z
  }|                                 }t          | ||          }|                                }t	          |dz
            }|                                |                                |                                z
  dz  z   }t	          ||                                dz  z
  dz
            }t          ||          }| 	                    |          }|
                    |                     |                     |                                 r|                                 }d}	nd}d}	|r|                                r|                                |	z   }
|
dk    r|                                 }|                                 | j        | j                            |
           |                    |
           | j        | j                                         |                                 d	S d	S d	S d	S )
zEnter array builder mode.r<   r%     r9      r   Trs   N)r0  rG   r   r=  rC   rH   bottomheightr   r7   r  rO   r#  is_python_likeexec_r   r)  r  r  r  r  r  r  )r.   inliner  r>  dlgrD   rE   r?  python_like_checksuffixr   r<   s               r/   r1  zBaseEditMixin._enter_arraye  s   ""8,,t/@/@/G/GG   vv66 IIKKBKKHHJJ$++--$((**4a77CJJLLN"Q&''Qll**3//!!#&&''' >> 	 $ 3 3 5 5FF !%F 
	& 
	&88::&Drzz**%%''',8-224888!!$'''-9.33555##%%%%%
	& 
	& 
	& 
	&zr1   )NNr  )r   )rn  r=  )T)FFT)TTFFF)rs   FFF)FFF)Yr`   
__module____qualname__r   r   _PARAMETER_HIGHLIGHT_COLOR_DEFAULT_TITLE_COLORr   COLOR_TEXT_2r   _DEFAULT_LANGUAGE_DEFAULT_MAX_LINES_DEFAULT_MAX_WIDTH"_DEFAULT_COMPLETION_HINT_MAX_WIDTH_DEFAULT_MAX_HINT_LINES_DEFAULT_MAX_HINT_WIDTHr  r  r  setr[   r0   r4   r7   rX   rh   rp   r   r   r   r   r   r
  r  r  r  r  r#  r0  rI   r;  r  rB  rE  rJ  rL  rS  rW  r`  rc  rf  rh  rk  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rn   r  r!  r#  r+  r.  r2  r4  r1  r3   r1   r/   r#   r#   <   s       !.!=(7)8'4 )+&     $ ceeO     
  
  ' ' ' 'R" " "$   "&D"&DD1#(Ek k k kZ 7;$6*D%:#4	k+ k+ k+ k+Z HL15.@->e7 e7 e7 e7N 15D/;M15# 5# 5# 5#n "&D"&4H!Du11 &+#'$(!D !D !D !DH 43 $T= = = =2# # #   ; ; ; ;<  	 	 	! ! !&$ $ $
- 
- 
-  % % %' ' '	; 	; 	; 	;1 1 1! ! !# # #? ? ? ?       ) ) ). . . .F F F$K K K KK K K K  5 5 54 4 4   .   2 2 2 2
. 
. 
.$ $ $) ) )V HM<@E E E EN ;@/3
 
 
 
% % %5 5 5@ @ @( ( (
L L L	 	 	, , ,
/ / /
L L L L, , , ,F F F
P 
P 
P 
P' ' '   2  < @E%*? ? ? ?B   @E.3   6        ! ! !#& #& #& #& #&r1   r#   c                   2    e Zd ZdZdZdZd Zd Zd Zd Z	dS )TracebackLinksMixinz=Mixin to make file names in tracebacks and anchors clickable.Nc                 L    d| _         d | _        |                     d           d S )NFT)$_TracebackLinksMixin__cursor_changedanchorsetMouseTrackingr-   s    r/   r0   zTracebackLinksMixin.__init__  s+     %d#####r1   c                    | j                             | |           |                     |                                          }t	          |          r9|                                 s%| j        | j                            |           dS dS | j        rBt          j
        t          | j                             t          j                     d| _        dS dS )zGo to error or link in anchor.N)QT_CLASSmouseReleaseEventr  r?  r   r  sig_go_to_error_requestedr  rP  r	   openUrlr   r   restoreOverrideCursorr.   eventr   s      r/   rT  z%TracebackLinksMixin.mouseReleaseEvent  s    ''e444		,,4   	)?)?)A)A 	-9.33D99999 :9[ 	$T$+%6%6777.000DKKK	 	r1   c                    |                      |                                          }|                     |                                          | _        t	          |          s| j        rB| j        s%t          j        t          j	                   d| _        |
                                 dS | j        rt          j                     d| _        | j                            | |           dS )z8Show pointing hand cursor on error messages and anchors.TNF)r  r?  anchorAtrP  r   rO  r   setOverrideCursorr   PointingHandCursoracceptrW  rS  mouseMoveEventrX  s      r/   r_  z"TracebackLinksMixin.mouseMoveEvent  s    		,,mmEIIKK004   	DK 	( -.r/DEEE(,%LLNNNF  	*.000$)D!$$T511111r1   c                 ~    | j         rt          j                     d| _         | j                            | |           dS )z.If cursor has not been restored yet, do it nowFN)rO  r   rW  rS  
leaveEvent)r.   rY  s     r/   ra  zTracebackLinksMixin.leaveEvent  sB      	*.000$)D!  u-----r1   )
r`   r@  rA  __doc__rS  rU  r0   rT  r_  ra  r3   r1   r/   rM  rM    sc        GGH !%$ $ $  2 2 2$. . . . .r1   rM  c                   0    e Zd Zd Zd Zd ZddZd	dZdS )
GetHelpMixinc                     d| _         d S NFhelp_enabledr-   s    r/   r0   zGetHelpMixin.__init__      !r1   c                     || _         d S r  rg  )r.   states     r/   set_help_enabledzGetHelpMixin.set_help_enabled  ri  r1   c                 d    |                                  }||                     |d           d S d S )NT)force)r  show_object_info)r.   r  s     r/   inspect_current_objectz#GetHelpMixin.inspect_current_object  s@    0022%!!.!===== &%r1   Fc                 l   t          |          }| j        p|}|r|dd}| j                            |           |rt	          | dd          r|                     |          }||r|                     |          }|                    d          d         }dx}	}
t          |t                    rg }|rdd
                    |          z   d	z   }	n8|                     |          }|!t          |          }	|	st          ||          }
|	s|
r)|	r||	z   }n|
}|                     |           dS dS dS dS dS dS )
z:Show signature calltip and/or docstring in the Help pluginF)rN   ignore_unknowncalltipsNr   r  rs   r   r   )r   rh  sig_help_requestedr  r   
iscallableget_arglistr   r   r  r   
get__doc__r   r   r   )r.   r   callrn  rh  docru  arglistrN   argspecr   r   s               r/   ro  zGetHelpMixin.show_object_info  s   d## (1E 	."' C #((---  	3GD*d33 	3..J% 3"..t44G JJsOOB/D*,,Gi!'400 %"$ 
L"%(8(8"83">"ood33? '9&=&=G#* L,@d,K,K	 3) 3" 0&*WnGG&/G))'222227	3 	3 	3 	3 &%3 3"3 3r1   c                 H    t          |                                 |          S )zB
        Return the last valid object on the current line
        )last)r   r  )r.   r}  s     r/   get_last_objzGetHelpMixin.get_last_obj  s#     d5577dCCCCr1   N)FF)F)r`   r@  rA  r0   rl  rp  ro  r~  r3   r1   r/   rd  rd    sp        " " "" " "> > >
)3 )3 )3 )3VD D D D D Dr1   rd  c                   2    e Zd ZdZdZg ZdZddZd Zd Z	dS )SaveHistoryMixinNrs   c                 <    || _         |                                  d S r  )history_filenamecreate_history_filename)r.   r  s     r/   r0   zSaveHistoryMixin.__init__  s"     0$$&&&&&r1   c                     | j         rLt          j        | j                   s5	 t          j        | j        | j                    dS # t          $ r Y dS w xY wdS dS )z=Create history_filename with INITHISTORY if it doesn't exist.N)r  ospisfiler   
writelinesINITHISTORYEnvironmentErrorr-   s    r/   r  z(SaveHistoryMixin.create_history_filename  s{      	D4I)J)J 	#D$4d6KLLLLL#   	 	 	 	s   A 
AAc                 j   t          |          }|dv s|                    d          rdS |                    d          r
|dd         }d| _        t	          | j                  dk    r| j        d         |k    rdS | j                            |           t          j        |z   }| j	        | j
        vr)| j
                            | j	                   | j        |z   }	 t          j        || j	        d           n# t          $ r Y nw xY w| j        "| j                            | j	        |           dS dS )	zAdd command to history)rs   r   	TracebackNr   r  r   abr  )r   r   endswithhistidxr   historyr   rM   r  r  HISTORY_FILENAMES	SEPARATORr   writer  sig_append_to_history_requestedr  )r.   commandr   s      r/   add_to_historyzSaveHistoryMixin.add_to_history  sb    ))j  G$6$6{$C$C FD!! 	#crclGt|q  T\"%5%@%@FG$$$zG#  (>>>"))$*?@@@>D(D	N4!6TBBBBB 	 	 	D	/;055%t- - - - - <;s   C: :
DD)rs   )
r`   r@  rA  r  r  r  r  r0   r  r  r3   r1   r/   r  r     s\        KI&*#' ' ' '  - - - - -r1   r  c                   &    e Zd Zd Zd Zd Zd ZdS )BrowseHistoryc                 0    g | _         d | _        d| _        d S rf  )r  r  hist_wholeliner-   s    r/   r0   zBrowseHistory.__init__3  s    #r1   c                     |t          |          k     r| j        rd| _        |d|         }|                     || j        |          \  }| _        |&|                                }| j        r|dfS ||z   dfS dS )zc
        Browse history.

        Return the new text and wherever the cursor should move.
        FNTrf  )r   r  find_in_historyr  r}   )r.   rV   r  backwardtocursorr   s         r/   browse_historyzBrowseHistory.browse_history8  s     D		!!d&9!"'D$!11(DL2:< <dl::<<D" .Tz!$--{r1   c                 N   |t          | j                  }|rdnd}|}t          |          dk    s| j        ri||z  }|t          | j                  k    st          | j                  dk    rdt          | j                  fS |dk     rd}d| _        | j        |         |fS t          t          | j                            D ]_}|||dz   z  z   t          | j                  z  }| j        |         }|                    |          r|t          |          d         |fc S `d|fS )z7Find text 'tocursor' in history, from index 'start_idx'Nr  r:   r   rs   T)r   r  r  rZ  r   )r.   r  	start_idxr  stepr   indexentrys           r/   r  zBrowseHistory.find_in_historyK  sG   DL))I$rr1x==A!44KCc$,''''3t|+<+<+A+A3t|,,,,q"&D<$c))s4<0011 ' ' uQw/3t|3D3DDS)##H-- 6 X0#55556 Y&r1   c                     d| _         dS )z3Reset the position from which to search the historyN)r  r-   s    r/   reset_search_poszBrowseHistory.reset_search_posc  s    r1   N)r`   r@  rA  r0   r  r  r  r3   r1   r/   r  r  1  sP        $ $ $
  &' ' '0    r1   r  c                   $     e Zd Zd Z fdZ xZS )BrowseHistoryMixinc                 <    |                      | j        d           dS )z4Clear current line (without clearing console prompt)r'  N)r  r  r-   s    r/   
clear_linezBrowseHistoryMixin.clear_linej  s!    0%88888r1   c                    |                      | j        d          }|                     d          }|                     d          | j        z
  }|dk     rd}|                     | j                   t	          t
          |                               |||          \  }}|B|                                  |                     |           |s|                     |           dS dS dS )zBrowse historyr'  r<   r   N)	r  r  r0  rW  superr  r  r  r  )r.   r  rV   old_posr  r   r`  r_   s          r/   r  z!BrowseHistoryMixin.browse_historyn  s    }}T4e<<##H--&&x0043JJ
>>J$$T%<===!"4d;;JJ*h( (kOOT""" 2((11111	 2 2r1   )r`   r@  rA  r  r  __classcell__)r_   s   @r/   r  r  h  sG        9 9 92 2 2 2 2 2 2 2 2r1   r  )3rb  rM   os.pathpathr  r   r  rK   r   packaging.versionr   qtpyr   qtpy.QtCorer   r   r   r   
qtpy.QtGuir	   r
   r   qtpy.QtWidgetsr   spyder_kernels.utils.dochelpersr   r   r   spyder.config.managerr   spyder.py3compatr   spyder.utilsr   r   r   r  spyder.utils.miscr   spyder.utils.paletter   spyder.widgets.arraybuilderr   r!  objectr#   rM  rd  r  r  r  r3   r1   r/   <module>r     s    
			       				     



  $ # # # # #       < < < < < < < < < < < < C C C C C C C C C C ' ' ' ' ' 'C C C C C C C C C C ' & & & & & + + + + + + - - - - - - - - 1 1 1 1 1 1 - - - - - - . . . . . . : : : : : :  $L& L& L& L& L&F L& L& L&^*3. 3. 3. 3. 3.& 3. 3. 3.l<D <D <D <D <D6 <D <D <D~.- .- .- .- .-v .- .- .-b4 4 4 4 4F 4 4 4n2 2 2 2 2 2 2 2 2 2r1   