IFT-575 Fix unexpected restore in Find in Files lesson

When we request `virtualFile`, we need to get the editor. But there can be the moment when the currently selected editor is null during new editor tab opening. It caused `NoTextEditor` exception and stop of the lesson.
Better to use more specific check here. But anyway, it looks like current behavior with `NoTextEditor` exception is not suitable and should be reconsidered.

GitOrigin-RevId: 5744726f8c0bf5089380f8417408a75ef125c45a
This commit is contained in:
Konstantin Hudyakov
2024-07-08 15:13:34 +03:00
committed by intellij-monorepo-bot
parent 75511b4159
commit d374db134e

View File

@@ -10,7 +10,10 @@ import com.intellij.find.impl.FindPopupItem
import com.intellij.find.impl.FindPopupPanel
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.impl.ActionButton
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.ui.UIUtil
import org.assertj.swing.core.MouseClickInfo
import org.assertj.swing.data.TableCell
@@ -110,7 +113,15 @@ open class FindInFilesLesson(override val sampleFilePath: String,
task {
text(LessonsBundle.message("find.in.files.go.to.file", LessonUtil.rawEnter()))
stateCheck { virtualFile.name != sampleFilePath.substringAfterLast('/') }
addFutureStep {
project.messageBus.connect(taskDisposable).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
if (file.name != sampleFilePath.substringAfterLast('/')) {
completeStep()
}
}
})
}
restoreState(delayMillis = defaultRestoreDelay) {
!isSelectedNeededItem(neededText)
}