replace
function replace(text, selection?): Replace;The answer of ctx.editing.shouldChangeText that puts another text in place of the text being typed.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
text |
string |
the new text of the field |
selection? |
{ end: number; start: number; } |
where the selection goes in the new text. When start and end are the same, it is the caret |
selection.end |
number |
- |
selection.start |
number |
- |
Returns
Section titled “Returns”{ replace: { text, selection? } }
Example
Section titled “Example”// two hyphens typed at the end of a title become a dashctx.editing.shouldChangeText({ topics: ['row.title'] }, change => change.resulting.endsWith('--') ? replace(change.resulting.slice(0, -2) + '—') : allow());