How to select multiple text and implement strikethrough functionality with track changes in TinyMCE?

21 views Asked by At

If I select text within multiple tags (for eg two consecutive p tags) then the selected contents get striked off in a new line, I know I am wrapping them inside a div but what other way can put the strikethrough functionality properly.

 if (
                        editor.selection.getContent() !== "" ||
                        (editor.selection.getContent() !== "" && event.key === " ")
                      ) {

                        const selectedBlocks = editor.selection.getSelectedBlocks();
                        const selectedContent = editor.selection.getContent({ format: "text" });
                         // Iterate over selected blocks to handle them individually
                        
                        if (selectedBlocks.length > 1) {
                          selectedBlocks.forEach((block) => {
                            const selectedContent = editor.selection.getContent({ format: "html" });
                            console.log(block.nodeName)
                            // Wraping the selected content within its original block tag

                            const modifiedContent = `<div class="del-input" id="deleted-${track_id}><${block.nodeName.toLowerCase()}">${selectedContent}</${block.nodeName.toLowerCase()}></div>`;
                            console.log(modifiedContent)
                            
                            editor.insertContent(modifiedContent);
  
                          });
                        }
                         
                        
                        else {
                          const selectedContent = editor.selection.getContent({ format: "html" });
                          editor.insertContent(`<span class="del-input" id=deleted-${track_id}>${selectedContent}</span>`);
                          
                        }

I tried multiple ways but didn't help.

0

There are 0 answers