Log changes in Color scheme font (via debug logger). Should help to investigate IJPL-157487 Use color scheme font instead of default option keeps on getting checked.

Loggers:
com.intellij.openapi.editor.colors.impl.AbstractColorsScheme
com.intellij.openapi.editor.colors.impl.EditorFontCacheImpl
com.intellij.openapi.editor.actions.ResetFontSizeActionBase
com.intellij.openapi.editor.impl.EditorImpl

(cherry picked from commit 173b9170edbcc83a6bf9d649866eb1aefb8765ff)

IJ-CR-147075

GitOrigin-RevId: 9bdd81bbe27adf728281afad32efa008c736c9ba
This commit is contained in:
Sergey Pak
2024-10-16 12:39:44 +00:00
committed by intellij-monorepo-bot
parent 06c7e18ea7
commit 23c1b47d6e
4 changed files with 91 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import com.intellij.configurationStore.SerializableScheme;
import com.intellij.ide.ui.ColorBlindness;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.*;
import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
@@ -34,6 +35,8 @@ import java.util.stream.Collectors;
@SuppressWarnings("UseJBColor")
public abstract class AbstractColorsScheme extends EditorFontCacheImpl implements EditorColorsScheme, SerializableScheme {
private static final Logger LOG = Logger.getInstance(AbstractColorsScheme.class);
public static final TextAttributes INHERITED_ATTRS_MARKER = new TextAttributes();
public static final Color INHERITED_COLOR_MARKER = JBColor.marker("INHERITED_COLOR_MARKER");
public static final Color NULL_COLOR_MARKER = JBColor.marker("NULL_COLOR_MARKER");
@@ -170,19 +173,38 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
public abstract Object clone();
public void copyTo(@NotNull AbstractColorsScheme newScheme) {
if (consoleFontPreferences instanceof DelegatingFontPreferences) {
boolean noName = newScheme.schemeName == null;
boolean consoleDelegating = consoleFontPreferences instanceof DelegatingFontPreferences;
boolean editorDelegating = fontPreferences instanceof DelegatingFontPreferences;
if (consoleDelegating) {
newScheme.setUseEditorFontPreferencesInConsole();
}
else {
if (LOG.isDebugEnabled()) {
LOG.debug("setConsoleFontPreferences: " + consoleFontPreferences.getFontFamily() + ":" + consoleFontPreferences.getSize(consoleFontPreferences.getFontFamily()));
}
newScheme.setConsoleFontPreferences(consoleFontPreferences);
}
if (fontPreferences instanceof DelegatingFontPreferences) {
if (editorDelegating) {
newScheme.setUseAppFontPreferencesInEditor();
}
else {
if (LOG.isDebugEnabled()) {
LOG.debug("setFontPreferences: " + fontPreferences.getFontFamily() +":"+fontPreferences.getSize(fontPreferences.getFontFamily()));
}
newScheme.setFontPreferences(fontPreferences);
}
if (LOG.isDebugEnabled()) {
String delegateInfo = ". Delegate info: Console: " + consoleDelegating + " Editor: " + editorDelegating;
if (noName) {
LOG.debug("Copying scheme " + debugSchemeName() + " to empty newScheme" + delegateInfo);
} else {
LOG.debug("Copying scheme " + debugSchemeName() + " to " + newScheme.debugSchemeName() + delegateInfo);
}
}
newScheme.attributesMap = new HashMap<>(attributesMap);
newScheme.colorMap = new HashMap<>(colorMap);
newScheme.version = version;
@@ -208,6 +230,9 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
@Override
public void setUseAppFontPreferencesInEditor() {
if (LOG.isDebugEnabled()) {
LOG.debug("setUseAppFontPreferencesInEditor in " + debugSchemeName());
}
fontPreferences = new DelegatingFontPreferences(() -> AppEditorFontOptions.getInstance().getFontPreferences());
initFonts();
}
@@ -253,6 +278,12 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
ModifiableFontPreferences currPreferences = ensureEditableFontPreferences();
boolean useLigatures = currPreferences.useLigatures();
float editorFontSize = getEditorFontSize2D();
if (LOG.isDebugEnabled()) {
String message = "setEditorFontName=%s for %s. Current name/size: %s:%.2f".formatted(
fontName, debugSchemeName(), currPreferences.getFontFamily(), editorFontSize);
Throwable stack = new Throwable(message);
LOG.debug(message, stack);
}
currPreferences.clear();
currPreferences.register(fontName, editorFontSize);
currPreferences.setUseLigatures(useLigatures);
@@ -271,8 +302,14 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
@Override
public void setEditorFontSize(float fontSize) {
fontSize = EditorFontsConstants.checkAndFixEditorFontSize(fontSize);
ensureEditableFontPreferences().register(fontPreferences.getFontFamily(), fontSize);
float fixedFontSize = EditorFontsConstants.checkAndFixEditorFontSize(fontSize);
if (LOG.isDebugEnabled()) {
String message = "setEditorFontSize for %s. %.2f (original: %.2f)".formatted(
debugSchemeName(), fixedFontSize, fontSize);
Throwable stack = new Throwable(message);
LOG.debug(message, stack);
}
ensureEditableFontPreferences().register(fontPreferences.getFontFamily(), fixedFontSize);
initFonts();
setSaveNeeded(true);
}
@@ -730,6 +767,12 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
if (!(fontPreferences instanceof ModifiableFontPreferences)) {
ModifiableFontPreferences editableFontPreferences = new FontPreferencesImpl();
fontPreferences.copyTo(editableFontPreferences);
if (LOG.isDebugEnabled()) {
String message = "ensureEditableFontPreferences in %s. %s, size: %d".formatted(
debugSchemeName(), editableFontPreferences, editableFontPreferences.getSize(editableFontPreferences.getFontFamily()));
Throwable stack = new Throwable(message);
LOG.debug(message, stack);
}
fontPreferences = editableFontPreferences;
((FontPreferencesImpl)fontPreferences).addChangeListener((source) -> initFonts());
}
@@ -1012,6 +1055,21 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement
sourceScheme.attributesMap.forEach((key, attributes) -> attributesMap.putIfAbsent(key, attributes));
}
private String debugSchemeName(){
try {
if (schemeName != null) {
return schemeName;
}
if (parentScheme == null) {
return null;
}
return parentScheme.getName();
} catch (Throwable e) {
LOG.warn("An exception occurred while trying to get scheme name", e);
return "null(e)";
}
}
private static @NotNull EditorColorsScheme getDefaultScheme(@NotNull String name) {
DefaultColorSchemesManager manager = DefaultColorSchemesManager.getInstance();
EditorColorsScheme defaultScheme = manager.getScheme(name);

View File

@@ -3,6 +3,7 @@ package com.intellij.openapi.editor.colors.impl;
import com.intellij.ide.ui.UISettings;
import com.intellij.ide.ui.UISettingsUtils;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.*;
import com.intellij.openapi.editor.impl.FontFamilyService;
import org.jetbrains.annotations.ApiStatus;
@@ -17,6 +18,8 @@ import java.util.Objects;
@ApiStatus.Internal
public class EditorFontCacheImpl extends EditorFontCache {
private static final Logger LOG = Logger.getInstance(EditorFontCacheImpl.class);
private static final Map<TextAttribute, Integer> LIGATURES_ATTRIBUTES = Map.of(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON);
private final @NotNull Map<EditorFontType, Font> fonts = new EnumMap<>(EditorFontType.class);
@@ -59,6 +62,18 @@ public class EditorFontCacheImpl extends EditorFontCache {
if (fallbackName != null) {
editorFontName = fallbackName;
}
if (LOG.isDebugEnabled()) {
String schemeName;
try {
schemeName = scheme.getName();
} catch (Throwable th) {
LOG.warn(th);
schemeName = "unknown(th)";
}
LOG.debug(String.format(
"Initializing fonts: scheme=%s, delegating=%b, fontName=%s, fontSize=%.2f",
schemeName, preferences instanceof DelegatingFontPreferences, editorFontName, editorFontSize));
}
setFont(EditorFontType.PLAIN, editorFontName, Font.PLAIN, editorFontSize, preferences);
setFont(EditorFontType.BOLD, editorFontName, Font.BOLD, editorFontSize, preferences);

View File

@@ -11,6 +11,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecification;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
@@ -31,6 +32,7 @@ class ResetFontSizeActionBase extends EditorAction implements ActionRemoteBehavi
static final String UNSCALED_FONT_SIZE_TO_RESET_EDITOR = "fontSizeToResetEditor";
public static final String PREVIOUS_COLOR_SCHEME = "previousColorScheme";
private final boolean myGlobal;
private static final Logger LOG = Logger.getInstance(ResetFontSizeActionBase.class);
@ApiStatus.Internal
public interface Strategy {
@@ -41,7 +43,11 @@ class ResetFontSizeActionBase extends EditorAction implements ActionRemoteBehavi
@NlsActions.ActionText String getText(float fontSize);
default void reset() {
setFontSize(getFontSize());
float size = getFontSize();
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Resetting font size to %.2f. Strategy: %s", size, getClass().getSimpleName() ));
}
setFontSize(size);
}
}

View File

@@ -459,7 +459,13 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
myView = new EditorView(this);
myView.reinitSettings();
if (LOG.isDebugEnabled()) {
float scaledEditorFontSize = UISettingsUtils.getInstance().getScaledEditorFontSize();
int currentFontSize = myScheme.getEditorFontSize();
LOG.debug(String.format(
"Creating editor view of type %s.\nCurrent font size: %d\nScaled font size: %f",
kind, currentFontSize, scaledEditorFontSize));
}
myScheme.setEditorFontSize(UISettingsUtils.getInstance().getScaledEditorFontSize());
myGutterComponent.updateSize();