nodegui / react-nodegui

Build performant, native and cross-platform desktop applications with native React + powerful CSS like styling.🚀
https://react.nodegui.org
MIT License
6.18k stars 171 forks source link

Getting selected text in PlainTextEdit #381

Open FanGoH opened 12 months ago

FanGoH commented 12 months ago

I am trying to get the selected text from a PlainTextEdit component

The snippet that I though of was

export const TextPart = () => {
  const textViewRef = createRef<QPlainTextEdit>(null);

  useEffect(() => {
    textViewRef.current.addEventListener("selectionChanged", () => {
      // How I should retrieve the selected text?
      textViewRef.current?.setPlainText("Hello World!");
    });

    return () => textViewRef.current.removeEventListener("selectionChanged");
  }, [textViewRef.current]);

  return (
    <View style="margin: 30px;">
      <Text>This is the cool part</Text>
      <PlainTextEdit ref={textViewRef} />
    </View>
  );
};

Which I though could help, but I don't think that the ref is giving me access to a @nodegui element.

How I could access the QPlainTextEdit element? Or how does the react wrapping works?