diff --git a/lisp/org.el b/lisp/org.el index abb173bc9..68e90ffe5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7947,8 +7947,7 @@ unchecked check box." (org-insert-heading (or (and (equal arg '(16)) '(16)) force-heading)) (save-excursion - (org-back-to-heading) - (outline-previous-heading) + (org-forward-heading-same-level -1) (let ((case-fold-search nil)) (looking-at org-todo-line-regexp))) (let* ((new-mark-x (if (or (equal arg '(4)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 3bc8c7b23..d067c04ff 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1415,6 +1415,13 @@ "* TODO \n" (org-test-with-temp-text "* H\n- an item\n- another one" (search-forward "an ") + (org-insert-todo-heading-respect-content) + (buffer-substring-no-properties (line-beginning-position) (point-max))))) + ;; Use the same TODO keyword as current heading. + (should + (equal + "* TODO \n" + (org-test-with-temp-text "* TODO\n** WAITING\n" (org-insert-todo-heading-respect-content) (buffer-substring-no-properties (line-beginning-position) (point-max))))))