react-native-rich-editor icon indicating copy to clipboard operation
react-native-rich-editor copied to clipboard

command & commandDOM not working

Open cbbernier opened this issue 3 years ago • 6 comments

Hi: I'm trying to change the global font size of the content in the DOM. I know setFontSize can resize the selection, but I need to resize most tags at once, like all div, pre, span, p, etc. The font size value is taken from a slider adjusted by the user. I'm tried to use commandDOM but it doesn't change anything. To access to font-size value, I tried different combinations of code like the examples below unsuccessfully: this.richText.current?.commandDOM(`$('body').style.font-size='${fontSize}'`); this.richText.current?.commandDOM(`$('body').style.fontSize='${fontSize}'`);

I saw the code for commandDOM on editor.js...I'm not sure I understand the syntax but is the actual command being passed down to the DOM? commandDOM: function (command){ try {new Function("$", command)(exports.document.querySelector.bind(exports.document))} catch(e){console.log(e.message)};

I also try to capture the ref of the webview inside RichEditor.js to use injectJavaScript method but that doesn't work either.

Thank you for your help.

cbbernier avatar Mar 16 '21 08:03 cbbernier

Hey! @cbbernier 👋 You forgot put the Measurement Unit such as px.

Here a working example ⬇️

this.richText.current?.commandDOM(`
    $('.content').style.fontSize = '${fontSize}px'; 
    $('.pell').style.fontSize = '${fontSize}px';
`);

Matiassimone avatar Apr 15 '21 20:04 Matiassimone

@cbbernier The elements below body may not accept body's own fontSize in some cases

stulip avatar May 24 '21 09:05 stulip

How do I remove an element with specific id? I want to remove <div id="some_specific_id">some content here</div> from editor content

akshitrcrm avatar Mar 13 '22 14:03 akshitrcrm

Even the following piece of code (from the readme) not working for me:

 // $ = document
 this.richText.current?.commandDOM('$.execCommand('insertHTML', false, "<br/>")');

I am getting the following error:

FROM EDIT: $.execCommand is not a function. (In '$.execCommand('insertHTML', false, "<br/>")', '$.execCommand' is undefined)

chiragbhaiji avatar Nov 01 '22 10:11 chiragbhaiji

How to change CSS Style from "direction: ltr;" to "direction: rtl;" ?

galiousmaze avatar Apr 25 '23 06:04 galiousmaze

Finally I make it work.

    richText.current?.commandDOM(
      `document.getElementById('${myId}').style.backgroundColor = 'orange';`,
    );

This is the only way that this works for me.

AugustoAleGon avatar Nov 01 '23 00:11 AugustoAleGon