menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

Programmatic find text/pattern in active editor

January 6, 2020 at 3:58pm

Programmatic find text/pattern in active editor

January 6, 2020 at 3:58pm (Edited 3 years ago)
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?

January 6, 2020 at 6:59pm
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.

January 7, 2020 at 4:46am
to get monaco editor: MonacoEditor(editorManager.activeEditor)

January 9, 2020 at 4:41pm
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
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)
}
}
Edited
like-fill
1