Skip to content

Commit

Permalink
Don't exit markup when there's content after the cursor
Browse files Browse the repository at this point in the history
FIX: `insertNewlineContinueMarkup` will no longer exit lists when there is content
after the cursor.

See https://discuss.codemirror.net/t/bug-with-markdown-command/3794
  • Loading branch information
marijnh committed Dec 10, 2021
1 parent 11312c9 commit 47a0ad5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/commands.ts
Expand Up @@ -102,7 +102,7 @@ export const insertNewlineContinueMarkup: StateCommand = ({state, dispatch}) =>
if (inner.to - inner.spaceAfter.length > pos - line.from) return dont = {range}

// Empty line in list
if (inner.item && pos >= (inner.to - inner.spaceAfter.length) && !/\S/.test(line.text.slice(inner.to, pos - line.from))) {
if (inner.item && pos >= (inner.to - inner.spaceAfter.length) && !/\S/.test(line.text.slice(inner.to))) {
// First list item or blank line before: delete a level of markup
if (inner.node.firstChild!.to >= pos ||
line.from > 0 && !/[^\s>]/.test(doc.lineAt(line.from - 1).text)) {
Expand Down
8 changes: 5 additions & 3 deletions test/test-commands.ts
Expand Up @@ -86,9 +86,6 @@ describe("insertNewlineContinueMarkup", () => {
test(" - one\n\n - |", " - one\n\n|")
})

it("can drop list markup even with text after it", () =>
test(" - one\n - |two", " - one\n\n - |two"))

it("deletes the first list marker", () =>
test(" - |", "|"))

Expand Down Expand Up @@ -118,6 +115,11 @@ describe("insertNewlineContinueMarkup", () => {

it("can lift out of one list level and renumber", () =>
test("1. a\n\n 1. b\n\n 2. |\n\n2. d", "1. a\n\n 1. b\n\n2. |\n\n3. d"))

it("doesn't treat lines with content after the cursor as empty", () => {
test("1. |x\n2. y", "1.\n2. |x\n3. y")
test("1. x\n2. |y", "1. x\n2.\n3. |y")
})
})

describe("deleteMarkupBackward", () => {
Expand Down

0 comments on commit 47a0ad5

Please sign in to comment.