Ckeditor select all occurrences of the word given

Closed
0
0

First of all, I tried to use the Find and Replace plugin from the link below  and attempted to find it using the command editor.execute('find', 'steam'); but I couldn’t succeed.

https://ckeditor.com/docs/ckeditor5/latest/features/find-and-replace.html

 

Secondly, when I tried the following code from this link with ckeditor.eval, it only finds the first match but cannot find the other matches.”

string eval = @”// Note: your instance name may differ.
var editor = this.editor,
selection = editor.getSelection(),
root = selection.root,
textNodes = [],
ranges = [],
range, text, index;

function getTextNodes( element ) {
var children = element.getChildren(),
child;

for ( var i = children.count(); i–; ) {
child = children.getItem( i );
if ( child.type == CKEDITOR.NODE_ELEMENT )
getTextNodes( child );
else if ( child.type == CKEDITOR.NODE_TEXT )
textNodes.push( child );
}
}

// Recursively search for text nodes starting from root.
// You may want to search a specific branch starting from other element.
getTextNodes( root );

// Iterate over found text nodes. If some contains
// phrase “”the””, create a range that selects this word.
for ( i = textNodes.length; i–; ) {
text = textNodes[ i ];
index = text.getText().indexOf( ‘erol’ );
if ( index > -1 ) {
range = editor.createRange();
range.setStart( text, index );
// Note: 3 is fixed length of “”the””. You may want to change it.
range.setEnd( text, index + 4 );
ranges.push( range );
}
}

// Select all ranges “”containing”” phrase “”the””.
selection.selectRanges( ranges );”;
ckEditor1.Eval(eval);

 

Is there an easier way to find all the matches?

  • You must to post comments
0
0

CKEditor is not our product. Please refer to their documentation and support.

  • Eray Yang
    Thank you for the response. Can we get results using the Find and Replace with CKEditor by using it as an external plugin and using with ckeditor.ExecCommand(“find”, “steam”)?
  • You must to post comments
Showing 1 result