
    AHjK                    n    d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
 erd dlmZ e G d d             Zy)	    )annotations)	dataclassfield)TYPE_CHECKING)
EditResultLocation	Selection)TextAreac                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	  ed	d
      Zded<   	  ed	d
      Zded<   	  ed	d
      Zded<   	 dddZ	ddZ
ddZedd       Zedd       Zy
)EditzQImplements the Undoable protocol to replace text at some range within a document.strtextr   from_locationto_locationboolmaintain_selection_offsetFN)initdefaultzSelection | None_original_selection_updated_selectionzEditResult | None_edit_resultc                8   |r|j                   | _        | j                  }| j                  \  }}|j                   \  }}|\  }}	|\  }
}|j                  j                  | j                  | j                  |      }|j                  \  }}||z
  }||k(  r
||	k  r|	|z   n|	}||
k(  r
||k  r||z   n|}||z
  }||k  r||z   n|}||
k  r|
|z   n|
}| j                  rt        ||f||f      | _
        n$t        j                  |j                        | _
        || _        |S )ax  Perform the edit operation.

        Args:
            text_area: The `TextArea` to perform the edit on.
            record_selection: If True, record the current selection in the TextArea
                so that it may be restored if this Edit is undone in the future.

        Returns:
            An `EditResult` containing information about the replace operation.
        )startend)	selectionr   r   bottomdocumentreplace_rangetopend_locationr   r	   r   cursorr   )self	text_arearecord_selectionr   edit_bottom_rowedit_bottom_columnselection_startselection_endselection_start_rowselection_start_columnselection_end_rowselection_end_columnedit_resultnew_edit_to_rownew_edit_to_columncolumn_offsettarget_selection_start_columntarget_selection_end_column
row_offsettarget_selection_start_rowtarget_selection_end_rows                        N/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/document/_edit.pydozEdit.do%   s~    '0':':D$yy /3kk++)2)<)<&6E332?//((66txxdS.9.F.F++*-?? "55"&<< #]2 (	 	& "33"&:: !=0 &	 	$ %6
 "55  *,$ 	# "33 
*" 	! ))&/13PQ-/JK'D#
 '0&6&6{7O7O&PD#'    c                    | j                   j                  }| j                   j                  }|j                  j	                  | j
                  ||      }| j                  | _        |S )a9  Undo the edit operation.

        Looks at the data stored in the edit, and performs the inverse operation of `Edit.do`.

        Args:
            text_area: The `TextArea` to undo the insert operation on.

        Returns:
            An `EditResult` containing information about the replace operation.
        )r   replaced_textr    r   r   r   r   r   )r"   r#   r:   edit_endundo_edit_results        r6   undoz	Edit.undoj   s`     ))77$$11 %--;;HHh
 #'":":r8   c                ^    | j                   | j                   |_        |j                          y)a  Hook for running code after an Edit has been performed via `Edit.do` *and*
        side effects such as re-wrapping the document and refreshing the display
        have completed.

        For example, we can't record cursor visual offset until we know where the cursor will
        land *after* wrapping has been performed, so we must wait until here to do it.

        Args:
            text_area: The `TextArea` this operation was performed on.
        N)r   r   record_cursor_width)r"   r#   s     r6   afterz
Edit.after   s*     ""."&"9"9I%%'r8   c                D    t        | j                  | j                  g      S )zMThe Location impacted by this edit that is nearest the start of the document.)minr   r   r"   s    r6   r   zEdit.top         D&&(8(89::r8   c                D    t        | j                  | j                  g      S )zKThe Location impacted by this edit that is nearest the end of the document.)maxr   r   rC   s    r6   r   zEdit.bottom   rD   r8   )T)r#   r
   r$   r   returnr   )r#   r
   rG   r   )r#   r
   rG   None)rG   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r7   r=   r@   propertyr   r    r8   r6   r   r      s    [
IH+(##S,1ud,K)KW+0eT+J(JG&+&EL#E'CJ ,( ; ; ; ;r8   r   N)
__future__r   dataclassesr   r   typingr   textual.document._documentr   r   r	   textual.widgetsr
   r   rO   r8   r6   <module>rU      s6    " (   F F( J; J; J;r8   