Skip to content

Commit

Permalink
Fix markdown-enter-key doesn't delete empty checkbox list
Browse files Browse the repository at this point in the history
  • Loading branch information
kuranari committed Aug 5, 2023
1 parent 50ac14f commit cef418c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- HTML-escape title in `markdown-add-xhtml-header-and-footer` [markdown-xwidget-issue-9](https://github.com/cfclrk/markdown-xwidget/issues/9)
- Fix wrong inline link parsing that has link title[GH-762][]
- Don't treat backslashes as escapes inside literal blocks[GH-766][] [GH-768][]
- Fix `markdown-enter-key` doesn't delete empty checkbox list

[gh-377]: https://github.com/jrblevin/markdown-mode/issues/377
[gh-572]: https://github.com/jrblevin/markdown-mode/issues/572
Expand Down
5 changes: 3 additions & 2 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5066,9 +5066,10 @@ list simply adds a blank line)."
(setq bounds (markdown-cur-list-item-bounds)))
(let ((beg (cl-first bounds))
(end (cl-second bounds))
(length (cl-fourth bounds)))
(nonlist-indent (cl-fourth bounds))
(checkbox (cl-sixth bounds)))
;; Point is in a list item
(if (= (- end beg) length)
(if (= (- end beg) (+ nonlist-indent (length checkbox)))
;; Delete blank list
(progn
(delete-region beg end)
Expand Down
12 changes: 12 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,18 @@ Should not cause an infinite loop."
(should (string-equal (buffer-string) "* foo\n* bar\n * baz\n\n"))
(should (eq (point) 22)))))

(ert-deftest test-markdown-indentation/indent-checkbox-list ()
"Test `markdown-indent-line' with a list item with checkbox."
(let ((markdown-indent-on-enter 'indent-and-new-item))
(markdown-test-string " * [x] item 1"
(end-of-line)
(call-interactively #'markdown-enter-key)
(should (string-equal (buffer-string) " * [x] item 1\n * [ ] "))
(should (eq (point) 24))
(call-interactively #'markdown-enter-key)
(should (string-equal (buffer-string) " * [x] item 1\n\n"))
(should (eq (point) 17)))))

(ert-deftest test-markdown-indentation/indent-pre ()
"Test `markdown-indent-line' with a pre block."
(markdown-test-string
Expand Down

0 comments on commit cef418c

Please sign in to comment.