diff --git a/Common/src/main/java/com/tabnineCommon/chat/ChatBrowser.kt b/Common/src/main/java/com/tabnineCommon/chat/ChatBrowser.kt index 3e882a7e..5a647540 100644 --- a/Common/src/main/java/com/tabnineCommon/chat/ChatBrowser.kt +++ b/Common/src/main/java/com/tabnineCommon/chat/ChatBrowser.kt @@ -9,6 +9,7 @@ import com.intellij.util.io.readText import com.intellij.util.net.HttpConfigurable import com.jetbrains.cef.JCefAppConfig import com.tabnineCommon.general.StaticConfig +import com.tabnineCommon.general.Utils.executeThread import org.cef.browser.CefBrowser import org.cef.browser.CefFrame import org.cef.handler.CefLoadHandler @@ -46,7 +47,7 @@ class ChatBrowser private constructor(project: Project) { val postMessageListener = JBCefJSQuery.create(browser) val copyCodeListener = JBCefJSQuery.create(browser) postMessageListener.addHandler { - handleIncomingMessage(it, project, browser) + executeThread { handleIncomingMessage(it, project, browser) } return@addHandler null } copyCodeListener.addHandler { diff --git a/Common/src/main/java/com/tabnineCommon/chat/commandHandlers/ChatMessageHandler.kt b/Common/src/main/java/com/tabnineCommon/chat/commandHandlers/ChatMessageHandler.kt index 24e71296..7134c122 100644 --- a/Common/src/main/java/com/tabnineCommon/chat/commandHandlers/ChatMessageHandler.kt +++ b/Common/src/main/java/com/tabnineCommon/chat/commandHandlers/ChatMessageHandler.kt @@ -2,11 +2,10 @@ package com.tabnineCommon.chat.commandHandlers import com.google.gson.Gson import com.google.gson.JsonElement -import com.intellij.ide.DataManager -import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.fileEditor.TextEditor import com.intellij.openapi.project.Project import com.tabnineCommon.chat.commandHandlers.utils.ActionPermissions import com.tabnineCommon.chat.commandHandlers.utils.AsyncAction @@ -18,12 +17,10 @@ abstract class ChatMessageHandler(protected val } protected fun getEditorFromProject(project: Project): Editor? { - return AsyncAction(ActionPermissions.WRITE).execute { + return AsyncAction(ActionPermissions.READ).execute { try { - val fileEditor = FileEditorManager.getInstance(project).selectedEditor ?: return@execute null - val dataContext = DataManager.getInstance().getDataContext(fileEditor.component) - - CommonDataKeys.EDITOR.getData(dataContext) + val fileEditor = FileEditorManager.getInstance(project).selectedEditor as? TextEditor + return@execute fileEditor?.editor } catch (e: Exception) { Logger.getInstance(javaClass).error("Failed to get editor from project: ", e) null