mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[PyCharm] Jupyter/RemoteDev (fix): Fixed notebooks behavior after sleep/suspend/lock screen. #PY-84624 Ready For Merge
(cherry picked from commit df21458da5043d4e799f414ea09bf8111f8dff00) (cherry picked from commit e544103848aa6a756f05398f6679687a13d73672) IJ-CR-183009 GitOrigin-RevId: b0e64117e3384976c725634542fa97a741488848
This commit is contained in:
committed by
intellij-monorepo-bot
parent
088e3789c2
commit
f0c8f16945
@@ -3,10 +3,8 @@ package com.intellij.notebooks.ui.editor.actions.command.mode
|
||||
|
||||
import com.intellij.injected.editor.EditorWindow
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.CaretVisualAttributes
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.ui.Gray
|
||||
import com.intellij.util.concurrency.ThreadingAssertions
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import com.intellij.util.messages.Topic
|
||||
@@ -31,15 +29,15 @@ val NOTEBOOK_EDITOR_MODE: Topic<NotebookEditorModeListener> = Topic.create("Note
|
||||
NotebookEditorModeListener::class.java)
|
||||
|
||||
@FunctionalInterface
|
||||
interface NotebookEditorModeListener {
|
||||
fun interface NotebookEditorModeListener {
|
||||
fun onModeChange(editor: Editor, mode: NotebookEditorMode)
|
||||
}
|
||||
|
||||
private val key = Key<NotebookEditorMode>("Jupyter Notebook Editor Mode")
|
||||
private val NOTEBOOK_EDITOR_MODE_KEY = Key<NotebookEditorMode>("Jupyter Notebook Editor Mode")
|
||||
|
||||
val Editor.currentMode: NotebookEditorMode
|
||||
get() {
|
||||
return getEditor().getUserData(key) ?: NotebookEditorMode.COMMAND
|
||||
return getEditor().getUserData(NOTEBOOK_EDITOR_MODE_KEY) ?: NotebookEditorMode.COMMAND
|
||||
}
|
||||
|
||||
private fun Editor.getEditor(): Editor {
|
||||
@@ -56,12 +54,9 @@ fun Editor.setMode(mode: NotebookEditorMode) {
|
||||
ThreadingAssertions.assertEventDispatchThread()
|
||||
|
||||
val modeChanged = mode != currentMode
|
||||
getEditor().putUserData(key, mode)
|
||||
getEditor().putUserData(NOTEBOOK_EDITOR_MODE_KEY, mode)
|
||||
|
||||
if (modeChanged) {
|
||||
ApplicationManager.getApplication().messageBus.syncPublisher(NOTEBOOK_EDITOR_MODE).onModeChange(this, mode)
|
||||
}
|
||||
}
|
||||
|
||||
internal val INVISIBLE_CARET = CaretVisualAttributes(Gray.TRANSPARENT,
|
||||
CaretVisualAttributes.Weight.NORMAL)
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.intellij.openapi.editor.ex.EditorEx
|
||||
import com.intellij.openapi.editor.ex.MarkupModelEx
|
||||
import com.intellij.openapi.editor.ex.RangeHighlighterEx
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil
|
||||
import com.intellij.ui.Gray
|
||||
|
||||
class NotebookEditorModeListenerAdapter private constructor(private val editor: Editor) : NotebookEditorModeListener, CaretListener, Disposable.Default {
|
||||
private var currentEditorMode: NotebookEditorMode? = null
|
||||
@@ -55,7 +56,7 @@ class NotebookEditorModeListenerAdapter private constructor(private val editor:
|
||||
|
||||
override fun caretAdded(event: CaretEvent) {
|
||||
val mode = currentEditorMode ?: return
|
||||
event.caret?.visualAttributes = getCaretAttributes(mode)
|
||||
event.caret.visualAttributes = getCaretAttributes(mode)
|
||||
(editor as EditorEx).gutterComponentEx.repaint()
|
||||
}
|
||||
|
||||
@@ -87,6 +88,8 @@ class NotebookEditorModeListenerAdapter private constructor(private val editor:
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val INVISIBLE_CARET = CaretVisualAttributes(Gray.TRANSPARENT, CaretVisualAttributes.Weight.NORMAL)
|
||||
|
||||
fun setupForEditor(editor: Editor) {
|
||||
val listener = NotebookEditorModeListenerAdapter(editor)
|
||||
editor.caretModel.addCaretListener(listener, listener)
|
||||
|
||||
Reference in New Issue
Block a user