Hello there,
I’ve recently created a button that changes the case of some selected text i.e. lowercase to uppercase and vice versa. When used on a bullet list of text nodes however, it concatenates the text e.g. a bullet list of 3 'hi’s would be turned into a single bullet point of ‘HI’. Does anyone know how to ensure that this concatenation does not occur?
Here is my code:
export function caseCommand() : ProsemirrorCommand {
return (state, dispatch) => {
const { from, to } = state.selection;
const text = state.doc.textBetween(from, to);
if (text.length === 0) {
return false;
} else if (text.toLowerCase() === text) {
const textNode = state.schema.text(text.toUpperCase());
dispatch(state.tr.replaceWith(from, to, textNode));
} else {
const textNode = state.schema.text(text.toLowerCase());
dispatch(state.tr.replaceWith(from, to, textNode));
}
return true;
}
}