Hello! Thank you very much for providing such an excellent editor!
I want to replace the specific user input with other input. for example, when someone inputs “a”, i will replace with ‘b’.
I use transactionFilter to do this and everything is well. But if i want to replace chinese character, it becomes strange. for example, replace ‘,’ with ‘,’ . like gif below.
It will insert ‘,’ twice.
and here is my extension code
EditorState.transactionFilter.of(tr => {
if (!tr.docChanged) {
return tr;
}
let replaceTr: TransactionSpec[] = [];
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
// if i repalce the chinese ',' with 'a', 'b' .... , everything is ok
if (tr.newDoc.slice(fromB, toB).toString() === ',') {
replaceTr = [{
changes: {
from: fromB,
to: toB,
insert: ","
},
sequential: true,
}];
}
});
return [tr, ...replaceTr]
})
Hope for your help. Thank you