hotfix pagebreak
This commit is contained in:
@@ -45,15 +45,23 @@ function toggleWrap(editor, before, after = before, placeholder = t("editor.form
|
||||
}
|
||||
|
||||
|
||||
export function insertPageBreak(editor) {
|
||||
function insertStandaloneLine(editor, content) {
|
||||
const { start, end } = selection(editor);
|
||||
const value = editor.value;
|
||||
const needsLeadingNewline = start > 0 && value[start - 1] !== "\n";
|
||||
const needsTrailingNewline = end >= value.length || value[end] !== "\n";
|
||||
const marker = `${needsLeadingNewline ? "\n" : ""}---${needsTrailingNewline ? "\n" : ""}`;
|
||||
const marker = `${needsLeadingNewline ? "\n" : ""}${content}${needsTrailingNewline ? "\n" : ""}`;
|
||||
editor.setRangeText(marker, start, end, "end");
|
||||
}
|
||||
|
||||
export function insertPageBreak(editor) {
|
||||
insertStandaloneLine(editor, "[PAGEBREAK]");
|
||||
}
|
||||
|
||||
export function insertHorizontalRule(editor) {
|
||||
insertStandaloneLine(editor, "---");
|
||||
}
|
||||
|
||||
function togglePrefix(editor, prefixFactory) {
|
||||
const { start, end } = selection(editor);
|
||||
const lineStart = editor.value.lastIndexOf("\n", start - 1) + 1;
|
||||
@@ -98,7 +106,8 @@ export function applyFormat(editor, format) {
|
||||
if (format === "table") toggleWrap(editor, `| ${t("editor.format.column1", {}, "Column 1")} | ${t("editor.format.column2", {}, "Column 2")} |\n| --- | --- |\n| `, ` | ${t("editor.format.value", {}, "value")} |`, t("editor.format.value", {}, "value"));
|
||||
if (format === "footnote") toggleWrap(editor, "", `[^1]\n\n[^1]: ${t("editor.format.footnote", {}, "Footnote text")}`, t("editor.format.textWithFootnote", {}, "Text with footnote"));
|
||||
if (format === "definition") toggleWrap(editor, "", `\n: ${t("editor.format.definition", {}, "Definition")}`, t("editor.format.term", {}, "Term"));
|
||||
if (format === "page-break" || format === "horizontal-rule") insertPageBreak(editor);
|
||||
if (format === "page-break") insertPageBreak(editor);
|
||||
if (format === "horizontal-rule") insertHorizontalRule(editor);
|
||||
editor.focus();
|
||||
editor.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user