refac
This commit is contained in:
@@ -21,6 +21,12 @@
|
|||||||
let variableValues = {};
|
let variableValues = {};
|
||||||
|
|
||||||
const submitHandler = async () => {
|
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);
|
onSave(variableValues);
|
||||||
show = false;
|
show = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -485,6 +485,17 @@
|
|||||||
focus();
|
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) => {
|
export const replaceVariables = (variables) => {
|
||||||
if (!editor || !editor.view) return;
|
if (!editor || !editor.view) return;
|
||||||
const { state, view } = editor;
|
const { state, view } = editor;
|
||||||
@@ -519,7 +530,7 @@
|
|||||||
|
|
||||||
// Apply replacements in reverse order to maintain correct positions
|
// Apply replacements in reverse order to maintain correct positions
|
||||||
replacements.reverse().forEach(({ from, to, text }) => {
|
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
|
// Only dispatch if there are changes
|
||||||
|
|||||||
Reference in New Issue
Block a user