Programmatic find text/pattern in active editor

It is known that we can modify contents of the current active editor programmatically in theia using EditorManager.

Now, I want find a text content or search a text content in the active editor to get the location of the line and character where the content is found. I am okay with using RegExp search. Any suggestion or solutions that are predefined in theia for the use of theia extension?

[original thread by Karthik Bhat K]

[Karthik Bhat K]

https://eclipse-theia.github.io/theia/docs/next/classes/file_search.filesearchserviceimpl.html#find

I found this. Hopefully this is what I am looking for. It would be great if get examples on data structures and usage in TypeDocs.

You can use underlying monaco api: https://github.com/microsoft/monaco-editor/blob/b5a0ee71c21319cc43292d690b605f2729df6918/monaco.d.ts#L1700-L1745

to get monaco editor: MonacoEditor(editorManager.activeEditor)

[Karthik Bhat K]

@anton-kosyakov Any chance I can get a working sample. MonacoEditor(editorManager.activeEditor) is not giving me findMatches method or ITextModel interface

try to call MonacoEditor.getControl().findMatches

[Karthik Bhat K]

Thanks for the input. I figured it out

import { MonacoEditor } from "@theia/monaco/lib/browser/monaco-editor";
        let currentEditor = MonacoEditor.getCurrent(this.editorManager);
        if (currentEditor != undefined) {
            let textModel = currentEditor.getControl().getModel()
            if (textModel !== null) {
                return textModel.findMatches(pattern, true, true, false, null, true, 1)
            }
        }