From f8ec59695b05ebf497f92907fc0e9461f9d648ff Mon Sep 17 00:00:00 2001 From: Art Pinch Date: Mon, 2 Aug 2021 19:45:42 +0300 Subject: [PATCH] Send font style before caret for speculative typing --- .../projector/server/idea/CaretInfoUpdater.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 a10c79dc..7a20ad20 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,8 +28,8 @@ 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.EditorFontType import com.intellij.openapi.editor.ex.EditorEx -import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.editor.markup.TextAttributes import org.jetbrains.projector.awt.PWindow @@ -45,6 +45,7 @@ import org.jetbrains.projector.server.util.FontCacher import org.jetbrains.projector.util.logging.Logger import sun.awt.AWTAccessor import java.awt.Component +import java.awt.Font import java.awt.peer.ComponentPeer import java.util.concurrent.TimeoutException import kotlin.concurrent.thread @@ -82,7 +83,6 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv } private fun loadCaretInfo(): ServerCaretInfoChangedEvent.CaretInfoChange { - val editorFont = EditorUtil.getEditorFont() val focusedEditor = getCurrentEditorImpl() ?: return ServerCaretInfoChangedEvent.CaretInfoChange.NoCarets val focusedEditorComponent = focusedEditor.contentComponent @@ -134,6 +134,7 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv val verticalScrollBarWidth = if (isVerticalScrollBarVisible) scrollPane.verticalScrollBar?.width ?: 0 else 0 val textColor = getTextColorBeforeCaret(focusedEditor) + val editorFont = getFontBeforeCaret(focusedEditor) ServerCaretInfoChangedEvent.CaretInfoChange.Carets( points, @@ -161,6 +162,19 @@ class CaretInfoUpdater(private val onCaretInfoChanged: (ServerCaretInfoChangedEv return color.rgb } + private fun getFontBeforeCaret(editor: EditorEx): Font { + val attrs = getTextAttributesBeforeCaret(editor) { it.fontType != Font.PLAIN } + + val editorFontType = when (attrs?.fontType) { + Font.BOLD -> EditorFontType.BOLD + Font.ITALIC -> EditorFontType.ITALIC + Font.BOLD or Font.ITALIC -> EditorFontType.BOLD_ITALIC + else -> EditorFontType.PLAIN + } + + return editor.colorsScheme.getFont(editorFontType) + } + private fun getTextAttributesBeforeCaret(editor: EditorEx, filter: (TextAttributes) -> Boolean): TextAttributes? { val caretOffset = readAction { editor.caretModel.offset }