list: Fix regression when inserting items

* lisp/org-list.el (org-list-insert-item): Fix splitting item.
* testing/lisp/test-org-list.el (test-org-list/insert-item): Add test.

Reported-by: Duianto - <otnaiud@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2020-07/msg00061.html>
This commit is contained in:
Nicolas Goaziou 2020-07-06 12:05:18 +02:00
parent c78db89106
commit 07a4a72862
2 changed files with 8 additions and 3 deletions

View File

@ -1330,14 +1330,14 @@ This function modifies STRUCT."
;; This means that the part between body start of body and
;; split point was removed. So we compute the offset and
;; shift item's positions accordingly. In any other case,
;; the item was simply shifted by ITEM-SIZE.
;; the item was simply shifted by SIZE-OFFSET.
((and split-line-p (not beforep) (>= p pos) (<= p item-end-no-blank))
(let ((offset (- pos item ind (length bullet) (length after-bullet))))
(setcar e (- p offset))
(setcar (nthcdr 6 e) (- end offset))))
(t
(setcar e (+ p item-size))
(setcar (nthcdr 6 e) (+ end item-size))))))
(setcar e (+ p size-offset))
(setcar (nthcdr 6 e) (+ end size-offset))))))
(push (list item ind bullet nil box nil (+ item item-size)) struct)
(setq struct (sort struct #'car-less-than-car))
;; If not BEFOREP, new item must appear after ITEM, so exchange

View File

@ -863,6 +863,11 @@ b. Item 2<point>"
(org-test-with-temp-text "1. A<point>\n\n2. \n\n3. B"
(org-insert-item)
(buffer-string))))
(should
(equal "1. a\n2. \n b\n3. c"
(org-test-with-temp-text "1. a<point>\n b\n2. c"
(org-insert-item)
(buffer-string))))
;; Preserve list visibility when inserting an item.
(should
(equal