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:
parent
9d7f8c62c5
commit
3178cad796
1 changed files with 14 additions and 6 deletions
|
|
@ -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);
|
||||||
tr.insert(from, state.schema.text(replaceTerm, marks));
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
}
|
}
|
||||||
|
|
@ -229,9 +233,13 @@ 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);
|
||||||
tr.insert(from, tr.doc.type.schema.text(replaceTerm, marks));
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue