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

Commit

Permalink
Send font style 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 87e2695 commit f8ec596
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit f8ec596

Please sign in to comment.