需要使用sync-fusion文档编辑器查找第二次出现的文本,并用红色突出显示文本。
根据文档,他们有findAll()方法,它在整个文档中查找文本并以黄色突出显示。有没有什么办法可以让我自定义突出显示的颜色,并且只在文档中找到第二次出现?
replaceAll() {
let textToFind = document.getElementById('find_text').value;
let textToReplace = document.getElementById('replace_text').value;
if (textToFind !== '') {
// Find all the occurences of given text
this.documenteditor.searchModule.findAll(textToFind);
if (this.documenteditor.searchModule.searchResults.length > 0) {
// Replace all the occurences of given text
this.documenteditor.searchModule.searchResults.replaceAll(textToReplace);
}
}
}
render() {
return (<div>
<button onClick={this.replaceAll.bind(this)}>Replace All</button>
<DocumentEditorComponent id="container" ref={(scope) => { this.documenteditor = scope; }} isReadOnly={false} enableSelection={true} enableEditor={true} enableSearch={true}/>
</div>);
}
发布于 2020-01-29 12:55:38
在使用find和findall执行搜索操作之后。
您可以自定义搜索结果。请参阅以下文档。
请尝试在搜索结果中设置索引。虽然所有文本都将突出显示,但基于索引的文本出现时将仅突出显示所选内容。请检查上面的文档是否适合您的需求,或者在找到第二个实例时分享您的用例场景。
此外,文档编辑器不提供任何自定义选项来突出显示搜索结果。
发布于 2020-02-12 16:16:17
关于定制搜索结果
文档编辑器的最新版本(17.4.49)提供了自定义搜索突出显示颜色的选项。请参考下面的示例代码
this.settings ={ searchHighlightColor:'red‘};
DocumentEditorContainerComponent id="container“ref={(scope) => { this.container = scope;}} style={{ 'display':'block','height':'590px‘}} documentEditorSettings={this.settings} enableToolbar={true} locale='en-US'/>
发行说明
https://ej2.syncfusion.com/react/documentation/release-notes/17.4.49/#document-editor
这将帮助您自定义搜索结果的突出显示颜色
https://stackoverflow.com/questions/59945023
复制相似问题