ó
    Ãu„jÛ:  ã                  óV  • S SK Jr  S SKJrJr  S SKJr  S SKJr  S SK	J
r
JrJrJr  S SKJrJr  \
(       a  S SKJrJr  S SKJr  S S	KJr  \S
   r \" \" \5      5      r \ " S S5      5       r\" SS9SS j5       rSS jr " S S\5      r " S S\5      r\\ \ 4   r!  " S S\5      r"g)é    )Úannotations)ÚABCÚabstractmethod)Ú	dataclass)Ú	lru_cache)ÚTYPE_CHECKINGÚ
NamedTupleÚTupleÚoverload)ÚLiteralÚget_args)ÚNodeÚQuery)Úcell_len)ÚSize)ú
Ú
Úc                  ó0   • \ rS rSr% SrS\S'    S\S'   Srg)	Ú
EditResulté   z5Contains information about an edit that has occurred.ÚLocationÚend_locationÚstrÚreplaced_text© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú¨C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\textual/document/_document.pyr   r      s   ‡ á?àÓØ:ØÓÚ%r$   r   i   )Úmaxsizec                ó$   • U R                  S5      $ )zÃEncode the input text as utf-8 bytes.

The returned encoded bytes may be retrieved from a cache.

Args:
    text: The text to encode.

Returns:
    The utf-8 bytes representing the input string.
zutf-8)Úencode©Útexts    r%   Ú_utf8_encoder+       s   € ð �;‰;�wÓÐr$   c                ó.   • SU ;   a  gSU ;   a  gSU ;   a  gg)z�Return the newline type used in this document.

Args:
    text: The text to inspect.

Returns:
    The Newline used in the file.
r   r   r   r   r)   s    r%   Ú_detect_newline_styler-   /   s%   € ð �ƒ~ØØ	�‹ØØ	�‹Øàr$   c                  ó�  • \ rS rSrSr\SS j5       r\\SS j5       5       r\\SS j5       5       r	\\SS j5       5       r
\SS j5       r\SS j5       r\SS	 j5       r  S       SS jjrSS jr\\SS j5       5       r\\SS j5       5       r\\SS j5       5       r\(       a  \S S j5       r\S!S j5       r\S"S j5       rSrg
)#ÚDocumentBaseéB   zvDescribes the minimum functionality a Document implementation must
provide in order to be used by the TextArea widget.c                ó   • g)a  Replace the text at the given range.

Args:
    start: A tuple (row, column) where the edit starts.
    end: A tuple (row, column) where the edit ends.
    text: The text to insert between start and end.

Returns:
    The new end location after the edit is complete.
Nr   )ÚselfÚstartÚendr*   s       r%   Úreplace_rangeÚDocumentBase.replace_rangeF   ó   � r$   c                ó   • g)z'The text from the document as a string.Nr   ©r2   s    r%   r*   ÚDocumentBase.textS   r7   r$   c                ó   • g)z/Return the line separator used in the document.Nr   r9   s    r%   ÚnewlineÚDocumentBase.newlineX   r7   r$   c                ó   • g)zÁGet the lines of the document as a list of strings.

The strings should *not* include newline characters. The newline
character used for the document can be retrieved via the newline
property.
Nr   r9   s    r%   ÚlinesÚDocumentBase.lines]   r7   r$   c                ó   • g)a  Returns the line with the given index from the document.

This is used in rendering lines, and will be called by the
TextArea for each line that is rendered.

Args:
    index: The index of the line in the document.

Returns:
    The str instance representing the line.
Nr   )r2   Úindexs     r%   Úget_lineÚDocumentBase.get_lineg   r7   r$   c                ó   • g)zæGet the text that falls between the start and end locations.

Args:
    start: The start location of the selection.
    end: The end location of the selection.

Returns:
    The text between start (inclusive) and end (exclusive).
Nr   ©r2   r3   r4   s      r%   Úget_text_rangeÚDocumentBase.get_text_rangeu   r7   r$   c                ó   • g)a  Get the size of the document.

The height is generally the number of lines, and the width
is generally the maximum cell length of all the lines.

Args:
    indent_width: The width to use for tab characters.

Returns:
    The Size of the document bounding box.
Nr   )r2   Úindent_widths     r%   Úget_sizeÚDocumentBase.get_size�   r7   r$   Nc                ó   • 0 $ )aœ  Query the tree-sitter syntax tree.

The default implementation always returns an empty list.

To support querying in a subclass, this must be implemented.

Args:
    query: The tree-sitter Query to perform.
    start_point: The (row, column byte) to start the query at.
    end_point: The (row, column byte) to end the query at.

Returns:
    A dict mapping captured node names to lists of Nodes with that name.
r   )r2   ÚqueryÚstart_pointÚ	end_points       r%   Úquery_syntax_treeÚDocumentBase.query_syntax_tree�   s	   € ð( ˆ	r$   c                ó   • g ©Nr   )r2   rN   s     r%   Úprepare_queryÚDocumentBase.prepare_query¥   s   € Ør$   c                ó   • g)ú,Returns the number of lines in the document.Nr   r9   s    r%   Ú
line_countÚDocumentBase.line_count¨   r7   r$   c                ó   • g)ú9Returns the location of the start of the document (0, 0).©r   r   r   r9   s    r%   r3   ÚDocumentBase.start­   s   € ð r$   c                ó   • g)ú0Returns the location of the end of the document.Nr   r9   s    r%   r4   ÚDocumentBase.end³   r7   r$   c                ó   • g rT   r   ©r2   Ú
line_indexs     r%   Ú__getitem__ÚDocumentBase.__getitem__º   s   € Ø7:r$   c                ó   • g rT   r   rc   s     r%   re   rf   ½   s   € Ø?Br$   c                ó   • g)úÁReturn the content of a line as a string, excluding newline characters.

Args:
    line_index: The index or slice of the line(s) to retrieve.

Returns:
    The line or list of lines requested.
Nr   rc   s     r%   re   rf   À   r7   r$   r   ©r3   r   r4   r   r*   r   Úreturnr   ©rk   r   ©rk   ÚNewline©rk   ú	list[str]©rB   Úintrk   r   ©r3   r   r4   r   rk   r   )rJ   rr   rk   r   )NN)rN   z'Query'rO   útuple[int, int] | NonerP   rt   rk   zdict[str, list['Node']])rN   r   rk   z'Query | None'©rk   rr   ©rk   r   ©rd   rr   rk   r   ©rd   Úslicerk   rp   ©rd   zint | slicerk   zstr | list[str])r   r   r   r    r!   r   r5   Úpropertyr*   r<   r?   rC   rG   rK   rQ   rU   rY   r3   r4   r   r   re   r#   r   r$   r%   r/   r/   B   sj  † ñ;ð ó
ó ð
ð Øó6ó ó ð6ð Øó>ó ó ð>ð Øóó ó ðð óó ðð ó	ó ð	ð óó ðð  /3Ø,0ð	àðð ,ðð *ð	ð
 
!õô,ð Øó;ó ó ð;ð Øóó ó ðð Øó?ó ó ð?ö à	Û:ó 
Ø:à	ÛBó 
ØBàóó ór$   r/   c                  ó  ^ • \ rS rSrSrSS jr\SS j5       r\SS j5       r\SS j5       r	SS jr
SS jrSS	 jr\SS
 j5       r\SU 4S jj5       r\SS j5       rSS jrSS jrSS jr\S S j5       r\S!S j5       rS"S jrSrU =r$ )#ÚDocumentéÌ   z-A document which can be opened in a TextArea.c                óÜ   • [        U5      U l         UR                  SS9U l         UR	                  [        [        5      5      (       d  U(       d  U R                  R                  S5        g g )NF)ÚkeependsÚ )r-   Ú_newlineÚ
splitlinesÚ_linesÚendswithÚtupleÚVALID_NEWLINESÚappend)r2   r*   s     r%   Ú__init__ÚDocument.__init__Ï   sW   € Ü!6°tÓ!<ˆŒØ3Ø!%§¡¸% Ð!@ˆŒð	ð �=‰=œœ~Ó.×/Ñ/¶tØ�K‰K×Ñ˜rÕ"ð 8<r$   c                ó   • U R                   $ )zîGet the document as a list of strings, where each string represents a line.

Newline characters are not included in at the end of the strings.

The newline character used in this document can be found via the `Document.newline` property.
©r„   r9   s    r%   r?   ÚDocument.linesÚ   s   € ð �{‰{Ðr$   c                óL   • U R                   R                  U R                  5      $ )zGet the text from the document.)r‚   Újoinr„   r9   s    r%   r*   ÚDocument.textä   s   € ð �}‰}×!Ñ! $§+¡+Ó.Ð.r$   c                ó   • U R                   $ )z<Get the Newline used in this document (e.g. '
', '
'. etc.))r‚   r9   s    r%   r<   ÚDocument.newlineé   s   € ð �}‰}Ðr$   c                ó¸   • U R                   nU Vs/ s H  n[        UR                  U5      5      PM     nn[        USS9n[	        U5      n[        XV5      $ s  snf )z·The Size of the document, taking into account the tab rendering width.

Args:
    tab_width: The width to use for tab indents.

Returns:
    The size (width, height) of the document.
r   )Údefault)r„   r   Ú
expandtabsÚmaxÚlenr   )r2   Ú	tab_widthr?   ÚlineÚcell_lengthsÚmax_cell_lengthÚheights          r%   rK   ÚDocument.get_sizeî   sU   € ð —‘ˆÙINÓOÊÀœ §¡°Ó!;Ö<ÉˆÐOÜ˜l°AÑ6ˆÜ�U“ˆÜ�OÓ,Ð,ùò Ps   ‘$Ac                ó  • [        X45      u  pEUu  pgUu  p‰UR                  5       n
UR                  [        [        5      5      (       a  U
R                  S5        U R                  nU R                  XE5      nU[        U5      :¼  a  SnOX¸   U	S nU[        U5      :¼  a  SnOX¶   SU nU
(       a$  XêS   -   U
S'   [        U
S   5      nU
S   U-   U
S'   O[        U5      nXí-   /n
X«XhS-   & U[        U
5      -   S-
  nUU4n[        UU5      $ )ah  Replace text at the given range.

This is the only method by which a document may be updated.

Args:
    start: A tuple (row, column) where the edit starts.
    end: A tuple (row, column) where the edit ends.
    text: The text to insert between start and end.

Returns:
    The EditResult containing information about the completed
        replace operation.
r�   Nr   éÿÿÿÿé   )
Úsortedrƒ   r…   r†   r‡   rˆ   r„   rG   r—   r   )r2   r3   r4   r*   ÚtopÚbottomÚtop_rowÚ
top_columnÚ
bottom_rowÚbottom_columnÚinsert_linesr?   r   Úafter_selectionÚbefore_selectionÚdestination_columnÚdestination_rowr   s                     r%   r5   ÚDocument.replace_rangeý   s0  € ô ˜e˜\Ó*‰ˆØ!ÑˆØ$*Ñ!ˆ
à—‘Ó(ˆØ�=‰=œœ~Ó.×/Ñ/à×Ñ Ô#à—‘ˆà×+Ñ+¨CÓ8ˆØœ˜U›Ó#Ø ‰Oà#Ñ/°°Ð?ˆOà”c˜%“jÓ Ø!Ñà$™~¨k¨zÐ:ÐæØ.¸a±Ñ@ˆL˜‰OÜ!$ \°"Ñ%5Ó!6ÐØ+¨BÑ/°/ÑAˆL˜Òä!$Ð%5Ó!6ÐØ,Ñ>Ð?ˆLà*6ˆg Q™Ð'Ø!¤C¨Ó$5Ñ5¸Ñ9ˆà'Ð);Ð<ˆÜ˜,¨Ó6Ð6r$   c                óN  • X:X  a  g[        X45      u  p4Uu  pVUu  pxU R                  n	XW:X  a
  X•   n
X¦U nU$ X•   nXpR                  S-
  ::  a  X—   OSnXÆS n[        US-   U5       H  nX°R                  Xž   -   -  nM     XpR                  :  a  X°R                  -  nX½SU -  nU$ )aÒ  Get the text that falls between the start and end locations.

Returns the text between `start` and `end`, including the appropriate
line separator character as specified by `Document._newline`. Note that
`_newline` is set automatically to the first line separator character
found in the document.

Args:
    start: The start location of the selection.
    end: The end location of the selection.

Returns:
    The text between start (inclusive) and end (exclusive).
r�   r    N)r¡   r„   rY   Úranger‚   )r2   r3   r4   r¢   r£   r¤   r¥   r¦   r§   r?   r™   Úselected_textÚ
start_lineÚend_lineÚrows                  r%   rG   ÚDocument.get_text_range/  sÓ   € ð ‹<Øä˜e˜\Ó*‰ˆØ!ÑˆØ$*Ñ!ˆ
Ø—‘ˆØÓ Ø‘>ˆDØ ¨MÐ:ˆMð Ðð ™ˆJØ,6¿/¹/ÈAÑ:MÓ,M�uÒ(ÐSUˆHØ& {Ð3ˆMÜ˜W q™[¨*Ö5�Ø§¡°±Ñ!;Ñ;’ñ 6ð ŸO™OÓ+Ø§¡Ñ.�Ø¨.¨=Ð!9Ñ9�àÐr$   c                ó,   • [        U R                  5      $ )rX   )r—   r„   r9   s    r%   rY   ÚDocument.line_countU  s   € ô �4—;‘;ÓÐr$   c                ó   >• [         TU ]  $ )r\   )Úsuperr3   )r2   Ú	__class__s    €r%   r3   ÚDocument.startZ  s   ø€ ô ‰w‰}Ðr$   c                óT   • U R                   S   nU R                  S-
  [        U5      4$ )r`   rŸ   r    )r„   rY   r—   )r2   Ú	last_lines     r%   r4   ÚDocument.end_  s)   € ð —K‘K ‘Oˆ	Ø—‘ !Ñ#¤S¨£^Ð4Ð4r$   c                ó¢   • Uu  p#U[        U R                  5      -  U-   n[        U5       H   nU[        U R                  U5      5      -  nM"     U$ )z¡Given a location, returns the index from the document's text.

Args:
    location: The location in the document.

Returns:
    The index in the document's text.
)r—   r<   r¯   rC   )r2   Úlocationr³   ÚcolumnrB   rd   s         r%   Úget_index_from_locationÚ Document.get_index_from_locatione  sN   € ð ‰ˆØ”c˜$Ÿ,™,Ó'Ñ'¨&Ñ0ˆÜ ž*ˆJØ”S˜Ÿ™ zÓ2Ó3Ñ3ŠEñ %àˆr$   c                óZ  • SU< S3nUS:  d  U[        U R                  5      :”  a  [        U5      eSn[        U R                  5      n[	        U R
                  5       H@  nU[        U R                  U5      5      -   U-   nX:  a  XQU-
  4s  $ X:X  a	  US-   S4s  $ UnMB     [        U5      e)a  Given a codepoint index in the document's text, returns the corresponding location.

Args:
    index: The index in the document's text.

Returns:
    The corresponding location.

Raises:
    ValueError: If the index is doesn't correspond to a location in the document.
zIndex z3 does not correspond to a location in the document.r   r    )r—   r*   Ú
ValueErrorr<   r¯   rY   rC   )r2   rB   Úerror_messageÚcolumn_indexÚnewline_lengthrd   Únext_column_indexs          r%   Úget_location_from_indexÚ Document.get_location_from_indext  s¼   € ð �U‘IÐPÐQð 	ð �1‹9˜¤ D§I¡I£Ó.Ü˜]Ó+Ð+àˆÜ˜TŸ\™\Ó*ˆÜ §¡Ö0ˆJàœs 4§=¡=°Ó#<Ó=Ñ=ÀÑNð ð Ó(Ø"¨LÑ$8Ð9Ò9ØÓ+Ø" Q™¨Ð*Ò*Ø,ŠLñ 1ô ˜Ó'Ð'r$   c                ó   • X   nU$ )z¢Returns the line with the given index from the document.

Args:
    index: The index of the line in the document.

Returns:
    The string representing the line.
r   )r2   rB   Úline_strings      r%   rC   ÚDocument.get_line”  s   € ð ‘kˆØÐr$   c                ó   • g rT   r   rc   s     r%   re   ÚDocument.__getitem__   s   € Ø36r$   c                ó   • g rT   r   rc   s     r%   re   rÏ   £  s   € Ø;>r$   c                ó    • U R                   U   $ )ri   rŒ   rc   s     r%   re   rÏ   ¦  s   € ð �{‰{˜:Ñ&Ð&r$   )r„   r‚   )r*   r   rk   ÚNonero   rl   rm   )r˜   rr   rk   r   rj   rs   ru   rv   )r¿   r   rk   rr   )rB   rr   rk   r   rq   rw   rx   rz   )r   r   r   r    r!   r‰   r{   r?   r*   r<   rK   r5   rG   rY   r3   r4   rÁ   rÉ   rC   r   re   r#   Ú__classcell__)r¹   s   @r%   r}   r}   Ì   sÌ   ø† Ù7ô	#ð óó ðð ó/ó ð/ð óó ðô-ô07ôd$ðL ó ó ð ð öó ðð ó5ó ð5ô
ô(ô@
ð Û6ó Ø6àÛ>ó Ø>÷	'ò 	'r$   r}   c                  ól   • \ rS rSr% SrSrS\S'    SrS\S'    \SS j5       r	\
SS j5       rSS	 jrS
rg)Ú	Selectioni¶  zùA range of characters within a document from a start point to the end point.
The location of the cursor is always considered to be the `end` point of the selection.
The selection is inclusive of the minimum point and exclusive of the maximum point.
r]   r   r3   r4   c                ó   • U " X5      $ )z‰Create a Selection with the same start and end point - a "cursor".

Args:
    location: The location to create the zero-width Selection.
r   )Úclsr¿   s     r%   ÚcursorÚSelection.cursorÇ  s   € ñ �8Ó&Ð&r$   c                ó   • U u  pX:H  $ )zBReturn True if the selection has 0 width, i.e. it's just a cursor.r   rF   s      r%   Úis_emptyÚSelection.is_emptyÐ  s   € ð ‰
ˆØ‰|Ðr$   c                ór   • [        U R                  S   U R                  S   45      u  p#X:¬  =(       a    X:*  $ )z0Check if the given line is within the selection.r   )r¡   r3   r4   )r2   Úyr¢   r£   s       r%   Úcontains_lineÚSelection.contains_lineÖ  s2   € ä˜dŸj™j¨™m¨T¯X©X°a©[Ð9Ó:‰ˆØ‰x×'˜A™KÐ'r$   r   N)r¿   r   rk   z'Selection')rk   Úbool)rÞ   rr   rk   rá   )r   r   r   r    r!   r3   r"   r4   ÚclassmethodrØ   r{   rÛ   rß   r#   r   r$   r%   rÕ   rÕ   ¶  sV   ‡ ñð
 €Eˆ8Óðð €CˆÓðð
 ó'ó ð'ð óó ð÷
(r$   rÕ   N)r*   r   rk   Úbytes)r*   r   rk   rn   )#Ú
__future__r   Úabcr   r   Údataclassesr   Ú	functoolsr   Útypingr   r	   r
   r   Útyping_extensionsr   r   Útree_sitterr   r   Útextual._cellsr   Útextual.geometryr   rn   Úsetr‡   r   r+   r-   r/   r}   rr   r   rÕ   r   r$   r%   Ú<module>rî      s¹   ðÝ "ç #Ý !Ý ß =Ó =ç /æß'å #Ý !à
Ð$Ñ
%€Ø 2Ù‘X˜gÓ&Ó'€Ø .ð ÷&ð &ó ð&ñ �4Ñó ó ð ôô&G�3ô GôTc'ˆ|ô c'ðL ��c�‰?€Ø Iô#(�
õ #(r$   