使用这个编辑器,我成功地将编辑器文本中的URL设置为红色,并加下划线作为锚标记。但是当我使用setContentHTML()时,光标会跳转或返回到编辑器的开头。
这是我的代码:
const regExp = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
const editorOnChange = (txt) => {
embeddedString = txt.replace(regExp, "<a style='text-decoration:underline;color:red;' href='$1' target='_blank'>$1</a>");
console.log(embeddedString);
richText.current?.setContentHTML(embeddedString);
}
<KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : "height"} style={{ flex: 1, }}>
<RichEditor style={{ flex: 1, }}
placeholder="Enter Comment..."
ref={richText}
//initialContentHTML={editorHtml }
onChange={ (txt)=> {editorOnChange(txt)}}
/>
</KeyboardAvoidingView>
当用户键入时,编辑器如何能够保持其光标位置,而不是在用户键入时光标跳到起点?