mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix: handle empty replace term in search and replace functionality (#1562)
- Fix 'Empty text nodes are not allowed' error when replace field is empty - Update both replace() and replaceAll() functions to check for empty replaceTerm
This commit is contained in:
@@ -198,9 +198,13 @@ const replace = (
|
|||||||
|
|
||||||
const marks = Array.from(marksSet);
|
const marks = Array.from(marksSet);
|
||||||
|
|
||||||
// Delete the old text and insert new text with preserved marks
|
// Delete the old text
|
||||||
tr.delete(from, to);
|
tr.delete(from, to);
|
||||||
|
|
||||||
|
// Only insert new text if replaceTerm is not empty (allows for deletion when replaceTerm is empty)
|
||||||
|
if (replaceTerm) {
|
||||||
tr.insert(from, state.schema.text(replaceTerm, marks));
|
tr.insert(from, state.schema.text(replaceTerm, marks));
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
}
|
}
|
||||||
@@ -229,10 +233,14 @@ const replaceAll = (
|
|||||||
|
|
||||||
const marks = Array.from(marksSet);
|
const marks = Array.from(marksSet);
|
||||||
|
|
||||||
// Delete and insert with preserved marks
|
// Delete the old text
|
||||||
tr.delete(from, to);
|
tr.delete(from, to);
|
||||||
|
|
||||||
|
// Only insert new text if replaceTerm is not empty (allows for deletion when replaceTerm is empty)
|
||||||
|
if (replaceTerm) {
|
||||||
tr.insert(from, tr.doc.type.schema.text(replaceTerm, marks));
|
tr.insert(from, tr.doc.type.schema.text(replaceTerm, marks));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user