From 47900480f0195170a60c47d53ef966d5d79e4e37 Mon Sep 17 00:00:00 2001 From: Maxim Popov Date: Fri, 14 Aug 2026 11:39:27 +0000 Subject: [PATCH] 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 (cherry picked from commit 2afe30b85a14331c8c11d4a95e88dcde1c9e3c1e) IJ-MR-218523 GitOrigin-RevId: e06ec11cc712348692cba7ff4f9175652635c4f1 --- .../com/jetbrains/python/console/PyConsoleEnterHandler.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/console/PyConsoleEnterHandler.kt b/python/src/com/jetbrains/python/console/PyConsoleEnterHandler.kt index 43ff0c1bcefe..ca701d48da92 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleEnterHandler.kt +++ b/python/src/com/jetbrains/python/console/PyConsoleEnterHandler.kt @@ -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)) } }