kge: : font sticks; one font per frame from the focused window

`: font NAME` was reverted on the next frame because the per-window
chooser re-applied the config's code/writing font, and with two windows
in different modes the font flipped every frame.

Fonts per edit mode now live on the primary Editor (EditorFonts),
shared with secondary windows like the buffer list. `: font` sets the
font for the current buffer's mode, and the frontend picks one font per
frame from the window with keyboard focus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 11:36:38 -08:00
co-authored by Claude Opus 5.5
parent 6dcfaa93ef
commit bcefbc978f
9 changed files with 122 additions and 28 deletions
+45
View File
@@ -49,6 +49,28 @@
#include "Swap.h"
// The GUI font for each edit mode. These are application settings, not
// per-window ones: there is one loaded font, so every window's Editor must
// agree on them (secondary windows share the primary's; SetSharedFonts).
// Seeded from kge.toml; `: font` changes the current buffer's mode's entry.
struct EditorFonts {
std::string code_font = "default";
std::string writing_font = "crimsonpro";
[[nodiscard]] const std::string &ForMode(EditMode m) const
{
return m == EditMode::Writing ? writing_font : code_font;
}
void SetForMode(EditMode m, const std::string &name)
{
(m == EditMode::Writing ? writing_font : code_font) = name;
}
};
class Editor {
public:
Editor();
@@ -590,6 +612,26 @@ public:
}
// Per-mode GUI fonts. A secondary window's Editor points at the
// primary's, like the shared buffer list.
void SetSharedFonts(EditorFonts *shared)
{
shared_fonts_ = shared;
}
[[nodiscard]] EditorFonts &Fonts()
{
return shared_fonts_ ? *shared_fonts_ : fonts_;
}
[[nodiscard]] const EditorFonts &Fonts() const
{
return shared_fonts_ ? *shared_fonts_ : fonts_;
}
// Swap manager access (for advanced integrations/tests)
[[nodiscard]] kte::SwapManager *Swap()
{
@@ -641,6 +683,9 @@ private:
std::unique_ptr<kte::SwapManager> swap_;
kte::SwapManager *shared_swap_ = nullptr; // set with shared_buffers_; not owned
EditorFonts fonts_;
EditorFonts *shared_fonts_ = nullptr; // the primary's, in a secondary window; not owned
// Kill ring (Emacs-like)
std::vector<std::string> kill_ring_;
std::size_t kill_ring_max_ = 60;