From 1b797b0cdb70abc6f2c9197ea9394e0a1d7d4cd9 Mon Sep 17 00:00:00 2001 From: Art Pinch Date: Tue, 3 Aug 2021 12:16:08 +0300 Subject: [PATCH] Send background color before caret for speculative typing --- gradle.properties | 2 +- .../projector/server/idea/CaretInfoUpdater.kt | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8cda9ec1..39ce9bc5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ intellijPluginVersion=1.1.2 javassistVersion=3.27.0-GA kotlinVersion=1.5.20 mockitoKotlinVersion=3.2.0 -projectorClientVersion=0b8efa96 +projectorClientVersion=7bff9b80 projectorClientGroup=com.github.JetBrains.projector-client targetJvm=11 # Give JitPack some time to build projector-client: diff --git a/projector-server/src/main/kotlin/org/jetbrains/projector/server/idea/CaretInfoUpdater.kt b/projector-server/src/main/kotlin/org/jetbrains/projector/server/idea/CaretInfoUpdater.kt index 7a20ad20..89ba69d7 100644 --- a/projector-server/src/main/kotlin/org/jetbrains/projector/server/idea/CaretInfoUpdater.kt +++ b/projector-server/src/main/kotlin/org/jetbrains/projector/server/idea/CaretInfoUpdater.kt @@ -28,6 +28,7 @@ package org.jetbrains.projector.server.idea import com.intellij.ide.DataManager import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.application.invokeAndWaitIfNeeded +import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorFontType import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.impl.EditorImpl @@ -135,6 +136,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv val textColor = getTextColorBeforeCaret(focusedEditor) val editorFont = getFontBeforeCaret(focusedEditor) + val backgroundColor = getBackgroundBeforeCaret(focusedEditor) ServerCaretInfoChangedEvent.CaretInfoChange.Carets( points, @@ -151,6 +153,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv lineAscent = lineAscent, verticalScrollBarWidth = verticalScrollBarWidth, textColor = textColor, + backgroundColor = backgroundColor, ) } } @@ -175,7 +178,23 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv return editor.colorsScheme.getFont(editorFontType) } - private fun getTextAttributesBeforeCaret(editor: EditorEx, filter: (TextAttributes) -> Boolean): TextAttributes? { + private fun getBackgroundBeforeCaret(editor: EditorEx): Int { + val attrs = getTextAttributesBeforeCaret(editor, { + if (it.priority >= 0) it.attrs else null + }) { it.backgroundColor != null } + + val color = attrs?.backgroundColor + ?: editor.colorsScheme.getColor(EditorColors.CARET_ROW_COLOR) + ?: editor.colorsScheme.defaultBackground + + return color.rgb + } + + private fun getTextAttributesBeforeCaret( + editor: EditorEx, + mapper: (ExtendedTextAttributes) -> TextAttributes? = { it.attrs }, + filter: (TextAttributes) -> Boolean + ): TextAttributes? { val caretOffset = readAction { editor.caretModel.offset } @@ -194,7 +213,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv it(editor, caretOffset, compareAndUpdate) } - return bestFitAttributes?.attrs + return bestFitAttributes?.let(mapper) } private fun getAttrsFromRangeHighlighters( @@ -203,7 +222,9 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv compareAndUpdate: (ExtendedTextAttributes) -> Unit, ) { - val rangeHighlighters = invokeAndWaitIfNeeded { editor.filteredDocumentMarkupModel.allHighlighters } + val rangeHighlighters = invokeAndWaitIfNeeded { + editor.filteredDocumentMarkupModel.allHighlighters + editor.markupModel.allHighlighters + } val startPos = caretOffset - 1