Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get selected text in th editor #369

Open
Bilal-Txend opened this issue Oct 1, 2024 · 2 comments
Open

How to get selected text in th editor #369

Bilal-Txend opened this issue Oct 1, 2024 · 2 comments

Comments

@Bilal-Txend
Copy link

Bilal-Txend commented Oct 1, 2024

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>
@stulip
Copy link
Member

stulip commented Nov 20, 2024

你需要选择文本后触发事件? 还是通过一个按钮点击后获取选择的文本?
Do you need to trigger an event after selecting text? Or can the selected text be obtained by clicking a button?

@Bayramito
Copy link

你需要选择文本后触发事件? 还是通过一个按钮点击后获取选择的文本? 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants