            (emdocs-emit-keypress-json
             (buffer-name) "delete" beg prev-length))))
   (unless emdocs-is-network-insert
-    (setq-local emdocs-undo-posn emdocs-undo-list)))
+    (setq-local emdocs-undo-posn emdocs-undo-list))
+  (unless emdocs-is-undo-insert
+    (emdocs-update-undo-list beg end prev-length)))
 
 (defun emdocs-before-change-function (beg end)
   "docstring"

             (/= beg end))
    (setq-local
     emdocs-undo-list
     (cons (list :type "delete" :point beg :end end
                 :content (buffer-substring-no-properties beg end)
                 :local (not emdocs-is-network-insert))
           emdocs-undo-list))))

  (emdocs-broadcast-message
   (concat
    (json-encode
     (list :buffer buffer
           :edit_type type
           :point point
           :content content))
    "\n")))

(defun emdocs-update-undo-list (beg end prev-length)
  "docstring"
  )

(defun emdocs-after-change-function (beg end prev-length)
  "docstring"
