mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
PY-72389 Markdown cells cannot create new lines
GitOrigin-RevId: bcd636dd42dfc8b38bb10fa1c3e265035956fc46
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fbf492d05e
commit
a403ce305d
@@ -80,7 +80,7 @@ object DefaultNotebookEditorAppearance : NotebookEditorAppearance,
|
||||
override fun getCellStripeColor(editor: EditorImpl, lines: IntRange): Color? {
|
||||
val isSelected = isCellSelected(editor, lines)
|
||||
val color = when {
|
||||
isSelected && currentMode() == NotebookEditorMode.COMMAND -> CELL_UNDER_CARET_COMMAND_MODE_STRIPE_COLOR
|
||||
isSelected && editor.currentMode == NotebookEditorMode.COMMAND -> CELL_UNDER_CARET_COMMAND_MODE_STRIPE_COLOR
|
||||
isSelected -> CELL_UNDER_CARET_EDITOR_MODE_STRIPE_COLOR
|
||||
else -> null
|
||||
}
|
||||
@@ -103,8 +103,8 @@ object DefaultNotebookEditorAppearance : NotebookEditorAppearance,
|
||||
return editor.colorsScheme.getColor(CELL_STRIPE_COLOR) ?: JBColor.GRAY
|
||||
}
|
||||
|
||||
override fun getCellLeftLineWidth(): Int =
|
||||
when (currentMode()) {
|
||||
override fun getCellLeftLineWidth(editor: Editor): Int =
|
||||
when (editor.currentMode) {
|
||||
NotebookEditorMode.EDIT -> EDIT_MODE_CELL_LEFT_LINE_WIDTH
|
||||
NotebookEditorMode.COMMAND -> COMMAND_MODE_CELL_LEFT_LINE_WIDTH
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ object NewUINotebookDiffEditorAppearanceSizes: NotebookEditorAppearanceSizes {
|
||||
override val EXTRA_PADDING_EXECUTION_COUNT = 0
|
||||
override val EXTRA_GUTTER_AREA_WIDTH_EXECUTION_COUNT = 0 // not needed, see JupyterEditorGutterExtraSpaceManager
|
||||
|
||||
override fun getCellLeftLineWidth(): Int = 10
|
||||
override fun getCellLeftLineWidth(editor: Editor): Int = 10
|
||||
override fun getCellLeftLineHoverWidth(): Int = 10
|
||||
|
||||
override fun getLeftBorderWidth(): Int =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.notebooks.ui.editor.actions.command.mode
|
||||
|
||||
import com.intellij.injected.editor.EditorWindow
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
@@ -11,10 +12,10 @@ import com.intellij.openapi.editor.event.CaretListener
|
||||
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.util.Key
|
||||
import com.intellij.util.concurrency.ThreadingAssertions
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import com.intellij.util.messages.Topic
|
||||
import org.jetbrains.annotations.CalledInAny
|
||||
import java.awt.Color
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,7 @@ val NOTEBOOK_EDITOR_MODE: Topic<NotebookEditorModeListener> = Topic.create("Note
|
||||
@FunctionalInterface
|
||||
interface NotebookEditorModeListener {
|
||||
|
||||
fun onModeChange(mode: NotebookEditorMode)
|
||||
fun onModeChange(editor: Editor, mode: NotebookEditorMode)
|
||||
}
|
||||
|
||||
class NotebookEditorModeListenerAdapter(private val editor: Editor) : NotebookEditorModeListener, CaretListener {
|
||||
@@ -71,7 +72,7 @@ class NotebookEditorModeListenerAdapter(private val editor: Editor) : NotebookEd
|
||||
}
|
||||
}
|
||||
|
||||
override fun onModeChange(mode: NotebookEditorMode) {
|
||||
override fun onModeChange(editor: Editor, mode: NotebookEditorMode) {
|
||||
val modeWasChanged = currentEditorMode != mode
|
||||
|
||||
currentEditorMode = mode
|
||||
@@ -104,9 +105,9 @@ class NotebookEditorModeListenerAdapter(private val editor: Editor) : NotebookEd
|
||||
NotebookEditorMode.COMMAND -> true
|
||||
})
|
||||
editor.contentComponent.enableInputMethods(when (mode) {
|
||||
NotebookEditorMode.EDIT -> true
|
||||
NotebookEditorMode.COMMAND -> false
|
||||
})
|
||||
NotebookEditorMode.EDIT -> true
|
||||
NotebookEditorMode.COMMAND -> false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,29 +122,34 @@ class NotebookEditorModeListenerAdapter(private val editor: Editor) : NotebookEd
|
||||
}
|
||||
}
|
||||
|
||||
private val key = Key<NotebookEditorMode>("Jupyter Notebook Editor Mode")
|
||||
|
||||
@CalledInAny
|
||||
fun currentMode(): NotebookEditorMode = currentMode_
|
||||
val Editor.currentMode: NotebookEditorMode
|
||||
get() {
|
||||
return getEditor().getUserData(key) ?: NotebookEditorMode.COMMAND
|
||||
}
|
||||
|
||||
private fun Editor.getEditor(): Editor {
|
||||
var editor = this
|
||||
while (editor is EditorWindow) {
|
||||
editor = editor.delegate
|
||||
}
|
||||
return editor
|
||||
}
|
||||
|
||||
@RequiresEdt
|
||||
fun setMode(mode: NotebookEditorMode) {
|
||||
fun Editor.setMode(mode: NotebookEditorMode) {
|
||||
// Although LAB-50 is marked as closed, the checks still aren't added to classes written in Kotlin.
|
||||
ThreadingAssertions.assertEventDispatchThread()
|
||||
|
||||
val modeChanged = mode != currentMode_
|
||||
currentMode_ = mode
|
||||
val modeChanged = mode != currentMode
|
||||
getEditor().putUserData(key, mode)
|
||||
|
||||
// may be call should be skipped if mode == currentMode_
|
||||
if (modeChanged) {
|
||||
ApplicationManager.getApplication().messageBus.syncPublisher(NOTEBOOK_EDITOR_MODE).onModeChange(mode)
|
||||
ApplicationManager.getApplication().messageBus.syncPublisher(NOTEBOOK_EDITOR_MODE).onModeChange(this, mode)
|
||||
}
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var currentMode_: NotebookEditorMode = NotebookEditorMode.EDIT
|
||||
|
||||
|
||||
|
||||
private val INVISIBLE_CARET = CaretVisualAttributes(
|
||||
Color(0, 0, 0, 0),
|
||||
CaretVisualAttributes.Weight.NORMAL)
|
||||
|
||||
@@ -61,7 +61,7 @@ interface NotebookEditorAppearanceSizes {
|
||||
|
||||
val EXTRA_PADDING_EXECUTION_COUNT: Int
|
||||
|
||||
fun getCellLeftLineWidth(): Int
|
||||
fun getCellLeftLineWidth(editor: Editor): Int
|
||||
fun getCellLeftLineHoverWidth(): Int
|
||||
fun getLeftBorderWidth(): Int
|
||||
val EXTRA_GUTTER_AREA_WIDTH_EXECUTION_COUNT: Int
|
||||
@@ -128,7 +128,7 @@ object DefaultNotebookEditorAppearanceSizes: NotebookEditorAppearanceSizes {
|
||||
override val EXTRA_PADDING_EXECUTION_COUNT = JBUI.scale(20)
|
||||
override val EXTRA_GUTTER_AREA_WIDTH_EXECUTION_COUNT = JBUI.scale(0)
|
||||
|
||||
override fun getCellLeftLineWidth(): Int = EDIT_MODE_CELL_LEFT_LINE_WIDTH
|
||||
override fun getCellLeftLineWidth(editor: Editor): Int = EDIT_MODE_CELL_LEFT_LINE_WIDTH
|
||||
override fun getCellLeftLineHoverWidth(): Int = COMMAND_MODE_CELL_LEFT_LINE_WIDTH
|
||||
|
||||
override fun getLeftBorderWidth(): Int =
|
||||
|
||||
@@ -133,7 +133,7 @@ class NotebookTextCellBackgroundLineMarkerRenderer(private val highlighter: Rang
|
||||
if (editor.getUserData(isFoldingEnabledKey) != true) {
|
||||
val appearance = editor.notebookAppearance
|
||||
appearance.getCellStripeColor(editor, lines)?.let {
|
||||
paintCellStripe(appearance, g, r, it, top, height)
|
||||
paintCellStripe(appearance, g, r, it, top, height, editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ inline fun paintNotebookCellBackgroundGutter(
|
||||
if (editor.getUserData(isFoldingEnabledKey) != true) {
|
||||
if (editor.editorKind == EditorKind.DIFF) return
|
||||
if (stripe != null) {
|
||||
paintCellStripe(appearance, g, r, stripe, top, height)
|
||||
paintCellStripe(appearance, g, r, stripe, top, height, editor)
|
||||
}
|
||||
if (stripeHover != null) {
|
||||
g.color = stripeHover
|
||||
@@ -62,9 +62,10 @@ fun paintCellStripe(
|
||||
stripe: Color,
|
||||
top: Int,
|
||||
height: Int,
|
||||
editor: Editor,
|
||||
) {
|
||||
g.color = stripe
|
||||
g.fillRect(r.width - appearance.getLeftBorderWidth(), top, appearance.getCellLeftLineWidth(), height)
|
||||
g.fillRect(r.width - appearance.getLeftBorderWidth(), top, appearance.getCellLeftLineWidth(editor), height)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +78,7 @@ fun paintCellGutter(inlayBounds: Rectangle,
|
||||
r: Rectangle) {
|
||||
val appearance = editor.notebookAppearance
|
||||
appearance.getCellStripeColor(editor, lines)?.let { stripeColor ->
|
||||
paintCellStripe(appearance, g, r, stripeColor, inlayBounds.y, inlayBounds.height)
|
||||
paintCellStripe(appearance, g, r, stripeColor, inlayBounds.y, inlayBounds.height, editor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ open class TaskRuntimeContext internal constructor(private val lessonExecutor: L
|
||||
|
||||
fun setSample(sample: LessonSample, setCaret: Boolean = true) {
|
||||
taskInvokeLater(ModalityState.nonModal()) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
TemplateManagerImpl.getTemplateState(editor)?.gotoEnd()
|
||||
(editor as? EditorEx)?.isViewer = false
|
||||
editor.caretModel.removeSecondaryCarets()
|
||||
@@ -72,7 +72,7 @@ open class TaskRuntimeContext internal constructor(private val lessonExecutor: L
|
||||
}
|
||||
|
||||
fun select(startLine: Int, startColumn: Int, endLine: Int, endColumn: Int) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
val blockStart = LogicalPosition(startLine - 1, startColumn - 1)
|
||||
val blockEnd = LogicalPosition(endLine - 1, endColumn - 1)
|
||||
|
||||
@@ -84,7 +84,7 @@ open class TaskRuntimeContext internal constructor(private val lessonExecutor: L
|
||||
}
|
||||
|
||||
fun caret(text: String, select: Boolean = false) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
val start = getStartOffsetForText(text) ?: return
|
||||
editor.caretModel.moveToOffset(start)
|
||||
if (select) {
|
||||
@@ -95,13 +95,13 @@ open class TaskRuntimeContext internal constructor(private val lessonExecutor: L
|
||||
|
||||
/** NOTE: [line] and [column] starts from 1 not from zero. So these parameters should be same as in editors. */
|
||||
fun caret(line: Int, column: Int) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
OpenFileDescriptor(project, virtualFile, line - 1, column - 1).navigateIn(editor)
|
||||
requestEditorFocus()
|
||||
}
|
||||
|
||||
fun caret(offset: Int) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
OpenFileDescriptor(project, virtualFile, offset).navigateIn(editor)
|
||||
requestEditorFocus()
|
||||
}
|
||||
@@ -139,7 +139,7 @@ open class TaskRuntimeContext internal constructor(private val lessonExecutor: L
|
||||
}
|
||||
|
||||
private fun setCaret(position: LessonSamplePosition) {
|
||||
lessonExecutor.lesson.beforeCaretApplied()
|
||||
lessonExecutor.lesson.beforeCaretApplied(editor)
|
||||
position.selection?.let { editor.selectionModel.setSelection(it.first, it.second) }
|
||||
editor.caretModel.moveToOffset(position.startOffset)
|
||||
requestEditorFocus()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package training.learn.course
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.popup.Balloon
|
||||
@@ -50,5 +51,5 @@ abstract class KLesson(@NonNls id: String, @Nls name: String) : Lesson(id, name)
|
||||
|
||||
private fun isDumb(project: Project) = DumbService.getInstance(project).isDumb
|
||||
|
||||
open fun beforeCaretApplied() { }
|
||||
open fun beforeCaretApplied(editor: Editor) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user