org-list: Another fix to item insertion

* lisp/org-list.el (org-list-insert-item): Fix typos. Add a check to
determine if an item really belongs to the part being split.
* testing/lisp/test-org-list.el (test-org-list/insert-item): Add test.
This commit is contained in:
Nicolas Goaziou 2020-04-10 16:06:05 +02:00
parent 8eef99306a
commit 8b988ee3a5
2 changed files with 12 additions and 7 deletions

View File

@ -1325,13 +1325,12 @@ This function modifies STRUCT."
(setcar (nthcdr 6 e) (+ end size-offset)))
;; Items starting after modified item fall into two
;; categories. If item was split, and current item was
;; located after split point, it was moved to the new
;; item. Practically speaking, this means that the part
;; between body start of body and split point was removed.
;; So we compute the offset and shit item's positions
;; accordingly. In any other case, the item was simply
;; shifted by ITEM-SIZE.
((and split-line-p (not beforep) (>= p pos))
;; located after split point, it was moved to the new item.
;; 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.
((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))))

View File

@ -787,6 +787,12 @@ b. Item 2<point>"
(let ((org-M-RET-may-split-line '((default . nil))))
(org-insert-item))
(buffer-string))))
;; Re-order automatically.
(should
(equal "1. A\n\n2. \n\n3. \n\n4. B"
(org-test-with-temp-text "1. A<point>\n\n2. \n\n3. B"
(org-insert-item)
(buffer-string))))
;; Preserve list visibility when inserting an item.
(should
(equal