How to know if user is typing in Console of PyCharm

已回答

I have a function that's called in typedHandler but I don't want to call it if the user is typing in console. How to achieve this?

0

Please clarify the issue. What console do you mean? A screenshot would be nice. What is the implementation, registration in plugin.xml, and what method is called?

0

Hi,

There is no open API for this, but you can try the following approach.

You can use com.jetbrains.python.console.completion.PythonConsoleAutopopupBlockingHandler#REPL_KEY to check whether the current context is PythonConsole, like PythonConsoleAutopopupBlockingHandler does it:

if (editor.getUserData(REPL_KEY) != null){
  // console context
} else {
  // not a console
}

Please keep in mind that this is a part of the plugin implementation, not open API, and it may stop working in the future.

An alternative could be checking whether the current virtual file is LightVirtualFile with “Python Console” name. It also may stop working in the future.

 

 

0

Hello, shouldn't this be solvable by editor.KIND == CONSOLE(the enum that editor class had) but I tried it and it wasn't working. Is this not a Console kind of editor? 

0

Hi,

I asked a responsible person about it. Due to vacation period, the answer may be significantly delayed. Please be patient.

0

Okay okay, no problem. It's not urgent. Thank you!

0

That was quick :) The possibility of doing it has been implemented and will be available starting with PyCharm 2023.3 EAP 1.

If editor.getVirtualFile().getUserData(CONSOLE_KEY) == true then an editor from the Python Console.

Regarding the solution with REPL_KEY - it is unreliable because it works only if runtime completion in the console is enabled, and it will be disabled by default in 2023.3.

0

请先登录再写评论。