diff --git a/src/commands.ts b/src/commands.ts index 2551762..03cd46f 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -32,18 +32,15 @@ class Context { } function getContext(node: SyntaxNode, doc: Text) { - let nodes = [] + let nodes: SyntaxNode[] = [], context: Context[] = [] for (let cur: SyntaxNode | null = node; cur; cur = cur.parent) { - if (cur.name == "ListItem" || cur.name == "Blockquote" || cur.name == "FencedCode") - nodes.push(cur) + if (cur.name == "FencedCode") return context + if (cur.name == "ListItem" || cur.name == "Blockquote") nodes.push(cur) } - let context = [] for (let i = nodes.length - 1; i >= 0; i--) { let node = nodes[i], match let line = doc.lineAt(node.from), startPos = node.from - line.from - if (node.name == "FencedCode") { - context.push(new Context(node, startPos, startPos, "", "", "", null)) - } else if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) { + if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) { context.push(new Context(node, startPos, startPos + match[0].length, "", match[1], ">", null)) } else if (node.name == "ListItem" && node.parent!.name == "OrderedList" && (match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) { diff --git a/test/test-commands.ts b/test/test-commands.ts index e4e071b..2e466af 100644 --- a/test/test-commands.ts +++ b/test/test-commands.ts @@ -146,9 +146,9 @@ describe("insertNewlineContinueMarkup", () => { test("1. x\n2. |y", "1. x\n2.\n3. |y") }) - it("doesn't continue lists in fenced code", () => { - test("- ```foo|", "- ```foo\n |") - test("> - ```foo|", "> - ```foo\n> |") + it("doesn't take effect in fenced code", () => { + test("- ```foo|", "- ```foo|") + test("> - ```foo|", "> - ```foo|") }) it("continues nested task lists at the right level", () => {