@@ -573,15 +573,19 @@ Must be a positive integer."
573573 (move-overlay context-area-ov (overlay-start context-area-ov) (1- (overlay-end context-area-ov))))
574574 (let ((prompt-field-ov (make-overlay (line-beginning-position ) (1+ (line-beginning-position )) (current-buffer ))))
575575 (overlay-put prompt-field-ov 'eca-chat-prompt-field t )
576- (overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face ))))
576+ (overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face )))
577+ ; ; Clear undo history so undo won't affect previous messages
578+ (setq buffer-undo-list nil ))
577579
578580(defun eca-chat--clear ()
579581 " Clear the chat for SESSION."
580582 (erase-buffer )
581583 (remove-overlays (point-min ) (point-max ))
582584 (insert " \n " )
583585 (eca-chat--insert-prompt-string)
584- (eca-chat--refresh-context))
586+ (eca-chat--refresh-context)
587+ ; ; Clear undo history after reset
588+ (setq buffer-undo-list nil ))
585589
586590(defun eca-chat--stop-prompt (session )
587591 " Stop the running chat prompt for SESSION."
@@ -612,13 +616,15 @@ Otherwise to a not loading state."
612616 (overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face ))
613617 (save-excursion
614618 (goto-char (overlay-start prompt-field-ov))
615- (delete-region (point ) (+ (point ) (length stop-text)))))))))
619+ (delete-region (point ) (+ (point ) (length stop-text))))))
620+ (setq buffer-undo-list nil ))))
616621
617622(defun eca-chat--set-prompt (text )
618623 " Set the chat prompt to be TEXT."
619624 (-some-> (eca-chat--prompt-field-start-point) (goto-char ))
620625 (delete-region (point ) (line-end-position ))
621- (insert text))
626+ (insert text)
627+ (setq buffer-undo-list nil ))
622628
623629(defun eca-chat--cycle-history (n )
624630 " Cycle history by N."
@@ -974,7 +980,8 @@ If `eca-chat-focus-on-open' is non-nil, the window is selected."
974980 (when eca-chat--last-user-message-pos
975981 (save-excursion
976982 (goto-char eca-chat--last-user-message-pos)
977- (insert content))))
983+ (insert content))
984+ (setq buffer-undo-list nil )))
978985
979986(defun eca-chat--add-text-content (text &optional overlay-key overlay-value )
980987 " Add TEXT to the chat current position.
@@ -987,7 +994,8 @@ Add a overlay before with OVERLAY-KEY = OVERLAY-VALUE if passed."
987994 (let ((ov (make-overlay (point ) (point ) (current-buffer ))))
988995 (overlay-put ov overlay-key overlay-value)))
989996 (insert text)
990- (point ))))
997+ (point ))
998+ (setq buffer-undo-list nil )))
991999
9921000(defun eca-chat--expandable-content-at-point ()
9931001 " Return expandable content overlay at point, or nil if none."
@@ -1041,7 +1049,8 @@ Applies LABEL-FACE to label and CONTENT-FACE to content."
10411049 (_ (insert " \n " ))
10421050 (ov-content (make-overlay start-point start-point (current-buffer ) nil t )))
10431051 (overlay-put ov-content 'eca-chat--expandable-content-content (propertize content 'line-prefix " " ))
1044- (overlay-put ov-label 'eca-chat--expandable-content-ov-content ov-content))))))
1052+ (overlay-put ov-label 'eca-chat--expandable-content-ov-content ov-content))))
1053+ (setq buffer-undo-list nil )))
10451054
10461055(defun eca-chat--update-expandable-content (id label content &optional append-content? )
10471056 " Update to LABEL and CONTENT the expandable content of id ID."
@@ -1537,7 +1546,8 @@ string."
15371546 (goto-char (line-end-position ))
15381547 (when (= (line-beginning-position ) (line-end-position ))
15391548 (insert " " ))
1540- (insert text)))
1549+ (insert text)
1550+ (setq buffer-undo-list nil )))
15411551
15421552; ; Public
15431553
@@ -1551,7 +1561,6 @@ string."
15511561 (read-only-mode -1 )
15521562 (setq-local eca-chat--history '())
15531563 (setq-local eca-chat--history-index -1 )
1554- (buffer-disable-undo )
15551564
15561565 ; ; Show diff blocks in markdown-mode with colors.
15571566 (setq-local markdown-fontify-code-blocks-natively t )
0 commit comments