From cc109ae609f500df69dda0a207aa0bee05e120eb Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Wed, 11 Jun 2025 13:01:58 +0300 Subject: [PATCH] [terminal] IJPL-188621 Reset to the console font if non-monospaced font was configured in the terminal settings Do it only once to fix the issue for all already affected users. GitOrigin-RevId: ff942c8668cd6da3b991d1958b91e6c5ea9e8645 --- .../terminal/TerminalFontSettingsService.kt | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalFontSettingsService.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalFontSettingsService.kt index 8701354106d3..db1e23f61ed7 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalFontSettingsService.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalFontSettingsService.kt @@ -3,6 +3,7 @@ package org.jetbrains.plugins.terminal import com.intellij.application.options.EditorFontsConstants import com.intellij.ide.ui.UISettingsUtils +import com.intellij.ide.util.RunOnceUtil import com.intellij.openapi.Disposable import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage @@ -82,7 +83,10 @@ class TerminalFontSettingsService : AppFontOptions() override fun loadState(state: TerminalFontSettingsState) { columnSpacing = TerminalColumnSpacing.ofFloat(state.COLUMN_SPACING) - super.loadState(state) + + if (!resetNonMonospacedFontsOnce(state)) { + super.loadState(state) + } // In the case of RemDev settings are synced from backend to frontend using `loadState` method. // So, notify the listeners on every `loadState` to not miss the change. @@ -108,6 +112,27 @@ class TerminalFontSettingsService : AppFontOptions() return currentScheme.consoleFontPreferences } + /** + * Because of initial misconfiguration of the settings (IJPL-188621), non-monospaced fonts may be stored in the [storedState]. + * This logic is intended to reset the font to the default value (from console settings) in this case. + * This reset will be performed only once, further calls will do nothing. + * + * @return whether reset was performed during this call. + */ + fun resetNonMonospacedFontsOnce(storedState: TerminalFontSettingsState): Boolean { + return RunOnceUtil.runOnceForApp("TerminalFontSettingsService.fixStoredNonMonospacedFonts") { + val adjustedState = if (!FontFamilyService.isMonospaced(storedState.FONT_FAMILY)) { + val newState = TerminalFontSettingsState(getConsoleFontPreferences()) + newState.FONT_SIZE_2D = storedState.FONT_SIZE_2D + newState.LINE_SPACING = storedState.LINE_SPACING + newState + } + else storedState + + super.loadState(adjustedState) + } + } + private fun fireListeners() { for (listener in listeners) { listener.fontSettingsChanged()