Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Send background color before caret for speculative typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ARTI1208 committed Aug 25, 2021
1 parent f8ec596 commit 1b797b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -151,6 +153,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv
lineAscent = lineAscent,
verticalScrollBarWidth = verticalScrollBarWidth,
textColor = textColor,
backgroundColor = backgroundColor,
)
}
}
Expand All @@ -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 }

Expand All @@ -194,7 +213,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv
it(editor, caretOffset, compareAndUpdate)
}

return bestFitAttributes?.attrs
return bestFitAttributes?.let(mapper)
}

private fun getAttrsFromRangeHighlighters(
Expand All @@ -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

Expand Down

0 comments on commit 1b797b0

Please sign in to comment.