Skip to content

Commit cef418c

Browse files
committed
Fix markdown-enter-key doesn't delete empty checkbox list
1 parent 50ac14f commit cef418c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- HTML-escape title in `markdown-add-xhtml-header-and-footer` [markdown-xwidget-issue-9](https://github.com/cfclrk/markdown-xwidget/issues/9)
3737
- Fix wrong inline link parsing that has link title[GH-762][]
3838
- Don't treat backslashes as escapes inside literal blocks[GH-766][] [GH-768][]
39+
- Fix `markdown-enter-key` doesn't delete empty checkbox list
3940

4041
[gh-377]: https://github.com/jrblevin/markdown-mode/issues/377
4142
[gh-572]: https://github.com/jrblevin/markdown-mode/issues/572

markdown-mode.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5066,9 +5066,10 @@ list simply adds a blank line)."
50665066
(setq bounds (markdown-cur-list-item-bounds)))
50675067
(let ((beg (cl-first bounds))
50685068
(end (cl-second bounds))
5069-
(length (cl-fourth bounds)))
5069+
(nonlist-indent (cl-fourth bounds))
5070+
(checkbox (cl-sixth bounds)))
50705071
;; Point is in a list item
5071-
(if (= (- end beg) length)
5072+
(if (= (- end beg) (+ nonlist-indent (length checkbox)))
50725073
;; Delete blank list
50735074
(progn
50745075
(delete-region beg end)

tests/markdown-test.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,18 @@ Should not cause an infinite loop."
20542054
(should (string-equal (buffer-string) "* foo\n* bar\n * baz\n\n"))
20552055
(should (eq (point) 22)))))
20562056

2057+
(ert-deftest test-markdown-indentation/indent-checkbox-list ()
2058+
"Test `markdown-indent-line' with a list item with checkbox."
2059+
(let ((markdown-indent-on-enter 'indent-and-new-item))
2060+
(markdown-test-string " * [x] item 1"
2061+
(end-of-line)
2062+
(call-interactively #'markdown-enter-key)
2063+
(should (string-equal (buffer-string) " * [x] item 1\n * [ ] "))
2064+
(should (eq (point) 24))
2065+
(call-interactively #'markdown-enter-key)
2066+
(should (string-equal (buffer-string) " * [x] item 1\n\n"))
2067+
(should (eq (point) 17)))))
2068+
20572069
(ert-deftest test-markdown-indentation/indent-pre ()
20582070
"Test `markdown-indent-line' with a pre block."
20592071
(markdown-test-string

0 commit comments

Comments
 (0)