Skip to content

Commit

Permalink
Prevent deleteMarkupBackward from acting on continued paragraphs
Browse files Browse the repository at this point in the history
FIX: Fix a bug in `deleteMarkupBackward` that would cause it to delete pieces
of continued paragraphs below list item markers.

See https://discuss.codemirror.net/t/markdown-input-exception/6133
  • Loading branch information
marijnh committed Mar 29, 2023
1 parent 1b5592c commit ac815db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ export const deleteMarkupBackward: StateCommand = ({state, dispatch}) => {
if (pos - line.from > spaceEnd && !/\S/.test(line.text.slice(spaceEnd, pos - line.from)))
return {range: EditorSelection.cursor(line.from + spaceEnd),
changes: {from: line.from + spaceEnd, to: pos}}
if (pos - line.from == spaceEnd) {
if (pos - line.from == spaceEnd &&
// Only apply this if we're on the line that has the
// construct's syntax, or there's only indentation in the
// target range
(!inner.item || line.from <= inner.item.from || !/\S/.test(line.text.slice(0, inner.to)))) {
let start = line.from + inner.from
// Replace a list item marker with blank space
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to)))
Expand Down
3 changes: 3 additions & 0 deletions test/test-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,7 @@ describe("deleteMarkupBackward", () => {

it("does noting in a continued list item", () =>
test("- Foo\n-\n |Welcome", "- Foo\n-\n |Welcome"))

it("doesn't delete normal text in continued list items", () =>
test("- \na |b", "- \na |b"))
})

0 comments on commit ac815db

Please sign in to comment.