This commit is contained in:
Timothy Jaeryang Baek
2026-03-07 17:52:58 -06:00
parent e303c3da3b
commit 7b2f597b30
2 changed files with 18 additions and 1 deletions
@@ -21,6 +21,12 @@
let variableValues = {};
const submitHandler = async () => {
// Normalize Windows CRLF (\r\n) to LF (\n) for all string values
for (const key of Object.keys(variableValues)) {
if (typeof variableValues[key] === 'string') {
variableValues[key] = variableValues[key].replace(/\r\n/g, '\n');
}
}
onSave(variableValues);
show = false;
};
+12 -1
View File
@@ -485,6 +485,17 @@
focus();
};
// Convert text to ProseMirror nodes, using hardBreak for newlines
const textToNodes = (state, text) => {
if (!text.includes('\n')) return state.schema.text(text);
const nodes = [];
text.split('\n').forEach((line, i) => {
if (i > 0) nodes.push(state.schema.nodes.hardBreak.create());
if (line) nodes.push(state.schema.text(line));
});
return nodes;
};
export const replaceVariables = (variables) => {
if (!editor || !editor.view) return;
const { state, view } = editor;
@@ -519,7 +530,7 @@
// Apply replacements in reverse order to maintain correct positions
replacements.reverse().forEach(({ from, to, text }) => {
tr = tr.replaceWith(from, to, text !== '' ? state.schema.text(text) : []);
tr = tr.replaceWith(from, to, text !== '' ? textToNodes(state, text) : []);
});
// Only dispatch if there are changes