Skip to content

Commit

Permalink
[VIM-3617] Set a recursion guard for obtaining the editor
Browse files Browse the repository at this point in the history
Function `selectedTextEditor` in some cases may create a new editor, what causes the recursion and IDE freeze. The guard should protect from it.
  • Loading branch information
AlexPl292 committed Dec 17, 2024
1 parent 1ce7a97 commit 077de91
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package com.maddyhome.idea.vim.ui.widgets.mode.listeners
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.RecursionManager
import com.intellij.openapi.wm.WindowManager
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.common.EditorListener
Expand Down Expand Up @@ -73,7 +74,15 @@ internal class ModeWidgetListener: ModeChangeListener, EditorListener, VimWidget

private fun getFocusedEditorForProject(editorProject: Project?): Editor? {
if (editorProject == null) return null
val fileEditorManager = FileEditorManager.getInstance(editorProject)
return fileEditorManager.selectedTextEditor
return recursionGuard.doPreventingRecursion(recursionKey, false) {
val fileEditorManager = FileEditorManager.getInstance(editorProject)
getFocusedEditorForProject(editorProject)
fileEditorManager.selectedTextEditor
}
}

companion object {
private val recursionGuard = RecursionManager.createGuard<Any>("IdeaVim.modeWidgetListener")
private val recursionKey = Any()
}
}

0 comments on commit 077de91

Please sign in to comment.