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 · 0 comments
Open

How to get selected text in th editor #369

Bilal-Txend opened this issue Oct 1, 2024 · 0 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>
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

1 participant