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]

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:

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)