You are replacing the entire selection which may (and in your described scenario does) intersect and contain multiple nodes. So in your example you are replacing a selection of list items with a single text node so the result you describe is correct. Instead you should find the text nodes within the selection and replace those. There’s a similar topic about changing the text case with an approach described here.
1 Like