react-native-rich-editor
react-native-rich-editor copied to clipboard
How to get selected text in th editor
Can i get any heIp @gevgasparyan, i want to know that how to get the selected text in react native rich pell editor, I tried the script solution mention in the closed is issue but it's only triggered when editor initizalize after intialize when i select the text from one point to other point i can get the selected text here is my Editor Component look like :
<ScrollView
style={[styles.scroll]}
keyboardDismissMode={"interactive"}
keyboardShouldPersistTaps="handled"
contentContainerStyle={{ height: editorHeight }}
ref={scrollRef}
scrollEventThrottle={20}
showsVerticalScrollIndicator={false}
automaticallyAdjustKeyboardInsets
onLayout={(event) => {
const { height } = event.nativeEvent.layout;
setScrollViewHeight(height);
}}
>
<RichEditor
initialFocus={false}
firstFocusEnd={false}
disabled={isOpen}
editorStyle={contentStyle}
ref={ref}
initialContentHTML={content}
style={styles.rich}
useContainer={true}
enterKeyHint={"go"}
injectedJavaScript={`(function() {
var value = window.getSelection().toString() || '';
window.ReactNativeWebView.postMessage(JSON.stringify({ data: {type: 'SELECTION_CHANGE', value } }));
void(0);
})();`}
editorInitializedCallback={editorInitializedCallback}
onChange={handleChange}
onHeightChange={handleHeightChange}
onPaste={handlePaste}
onKeyUp={handleKeyUp}
onKeyDown={handleKeyDown}
onInput={handleInput}
onCursorPosition={(e) => handleCursorPosition(e)}
androidHardwareAccelerationDisabled={true}
pasteAsPlainText={true}
onMessage={handleOnMessage}
/>
</ScrollView>
你需要选择文本后触发事件? 还是通过一个按钮点击后获取选择的文本? Do you need to trigger an event after selecting text? Or can the selected text be obtained by clicking a button?
你需要选择文本后触发事件? 还是通过一个按钮点击后获取选择的文本? Do you need to trigger an event after selecting text? Or can the selected text be obtained by clicking a button?
I actually need same feature too, i need to select a text and add link to it for example