saros
saros copied to clipboard
Adjust handling of requesting text editors
Currently, the logic to obtain Editor objects for open text editors still causes the editor to be selected, even if the flag focusEditor=false is used.
This could possibly be avoided by using the logic to obtain open FileEditor objects, checking for TextEditor instances and then using TextEditor.getEditor() to obtain the needed object.
Subsequently, all calls that currently use ProjectAPI.openEditor(...) to obtain an editor object for a file that is known to be open in an editor (instead of actually wanting to open an editor) should be replaces with a call to this new logic.
Afterwards, the class SelectedEditorStateSnapshot could possibly be obsolete, meaning it could be removed.
Possible implementation for the new call in ProjectAPI
public static Editor getOpenTextEditor(@NotNull Project project, @NotNull VirtualFile file) {
FileEditorManager fileEditorManager = getFileEditorManager(project);
FileEditor[] fileEditors = EDTExecutor.invokeAndWait(() -> fileEditorManager.getEditors(file));
for (FileEditor fileEditor : fileEditors) {
if (fileEditor instanceof TextEditor) {
TextEditor textEditor = (TextEditor) fileEditor;
return textEditor.getEditor();
}
}
return null;
}