PY-90740 [debugger]: fix Enter in the debug console when several projects share one backend

The platform enter handler takes its project from the data context it is handed,
not from the editor, and refuses to run when the two disagree. The console enter
handler built that context from the console editor's Swing component, where
CommonDataKeys.PROJECT can only come from an ancestor of that component: with
several projects open on one remote development backend the ancestor reports
another project, PsiUtilBase.assertEditorAndProjectConsistent throws inside the
write command, and Enter does nothing at all -- no line break, nothing sent to
the interpreter.

Use EditorUtil.getEditorDataContext instead, the platform utility written for
exactly this mismatch: it builds the context from the editor's content component
and overrides the project with the editor's own. It also restores EDITOR and
CARET in the context, which the component-based call dropped because those are
provided by the deeper editor component.


Merge-request: IJ-MR-218523
Merged-by: Maxim Popov <maxim.popov@jetbrains.com>

(cherry picked from commit 2afe30b85a14331c8c11d4a95e88dcde1c9e3c1e)

IJ-MR-218523

GitOrigin-RevId: e06ec11cc712348692cba7ff4f9175652635c4f1
This commit is contained in:
Maxim Popov
2026-08-17 21:47:58 +00:00
committed by intellij-monorepo-bot
parent cf903ad9b2
commit 47900480f0
@@ -15,12 +15,12 @@
*/
package com.jetbrains.python.console
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.actionSystem.EditorActionManager
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
@@ -88,7 +88,9 @@ class PyConsoleEnterHandler {
private fun executeEnterHandler(project: Project, editor:EditorEx) {
val enterHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER)
WriteCommandAction.runWriteCommandAction(project) {
enterHandler.execute(editor, null, DataManager.getInstance().getDataContext(editor.component))
// The enter handler takes its project from the data context, and the console editor's Swing ancestors may
// report another project when several projects share one remote development backend (PY-90740).
enterHandler.execute(editor, null, EditorUtil.getEditorDataContext(editor))
}
}