Throw errors when too many 'cursor' found in doc (#13339)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-08-26 21:33:49 +08:00
1 parent 286c354c46
commit d921087d12
2 files changed
+13

No files matched your search

+5
View File
@@ -294,6 +294,7 @@ function printDocToString(doc, options) {
let shouldRemeasure = false;
/** @type Command[] */
const lineSuffix = [];
let printedCursorCount = 0;
while (cmds.length > 0) {
const { ind, mode, doc } = cmds.pop();
@@ -313,7 +314,11 @@ function printDocToString(doc, options) {
}
case DOC_TYPE_CURSOR:
if (printedCursorCount >= 2) {
throw new Error("There are too many 'cursor' in doc.");
}
out.push(CURSOR_PLACEHOLDER);
printedCursorCount++;
break;
case DOC_TYPE_INDENT:
+8
View File
@@ -0,0 +1,8 @@
import { cursor } from "../../src/document/builders.js";
import { printDocToString } from "../../src/document/printer.js";
test("Should reject if too many cursor in doc", () => {
expect(() => {
printDocToString([cursor, cursor, cursor], { printWidth: 80, tabWidth: 2 });
}).toThrow({ message: "There are too many 'cursor' in doc." });
});