Eray Yang asked 2024-02-15 14:32:39 UTC
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
, 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?
Eray Yang asked 2024-02-15 14:32:39 UTC
First of all, I tried to use the Find and Replace plugin from the link below and attempted to find it using the command
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
, 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?