IJOB-569 Fix 'The editor has been closed' warning in Declaration and Usages lesson

Do not use `editor` property from the runtime context because it can throw an exception (and then warning in the Learn panel) if currently selected editor is null.
Because of the platform implementation, selected editor can be null at the moment between switching the editor tabs.


(cherry picked from commit dc3afe43eb8be4ff8e7993a0da35093577e2f118)

IJ-CR-147744

GitOrigin-RevId: 37571fa1905b762c6e3c8b2d6bad09ce9af6fdbb
This commit is contained in:
Konstantin Hudyakov
2024-10-23 17:36:54 +03:00
committed by intellij-monorepo-bot
parent 5395d08330
commit 1051f5cabc

View File

@@ -52,7 +52,7 @@ abstract class DeclarationAndUsagesLesson
task("GotoDeclaration") { actionId ->
text(LessonsBundle.message("declaration.and.usages.show.usages", action(actionId)))
stateCheck l@{
val curEditor = editor
val curEditor = FileEditorManager.getInstance(project).selectedTextEditor ?: return@l false
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(curEditor.document) ?: return@l false
val offset = curEditor.caretModel.offset
val element = psiFile.findElementAt(offset) ?: return@l false