Add proportional fonts, edit modes, and TOML config
- Add three proportional serif fonts: Crimson Pro, ET Book, Spectral - Fix text rendering for variable-width fonts: selection, cursor, mouse click mapping, search highlights, and syntax-colored text now use pixel-accurate measurement via ImGui::CalcTextSize() - Add per-buffer edit mode (code/writing) with auto-detection from file extension (.txt, .md, .rst, .org, .tex default to writing) - Add C-k m keybinding and :mode command to toggle edit modes - Switch config format from INI to TOML (kge.toml), with legacy INI fallback; vendor toml++ v3.4.0 - New config keys: font.code and font.writing for per-mode defaults - Add font tab completion for ImGui builds - Add tab completion for :mode command - Update help text, themes.md, and add CONFIG.md - Bump version to 1.10.0 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
47
Buffer.h
47
Buffer.h
@@ -35,9 +35,12 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
@@ -48,6 +51,26 @@
|
||||
#include "Highlight.h"
|
||||
#include <mutex>
|
||||
|
||||
// Edit mode determines which font class is used for a buffer.
|
||||
enum class EditMode { Code, Writing };
|
||||
|
||||
// Detect edit mode from a filename's extension.
|
||||
inline EditMode
|
||||
DetectEditMode(const std::string &filename)
|
||||
{
|
||||
std::string ext = std::filesystem::path(filename).extension().string();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
static const std::unordered_set<std::string> writing_exts = {
|
||||
".txt", ".md", ".markdown", ".rst", ".org",
|
||||
".tex", ".adoc", ".asciidoc",
|
||||
};
|
||||
if (writing_exts.count(ext))
|
||||
return EditMode::Writing;
|
||||
return EditMode::Code;
|
||||
}
|
||||
|
||||
// Forward declaration for swap journal integration
|
||||
namespace kte {
|
||||
class SwapRecorder;
|
||||
@@ -484,6 +507,27 @@ public:
|
||||
}
|
||||
|
||||
|
||||
// Edit mode (code vs writing)
|
||||
[[nodiscard]] EditMode GetEditMode() const
|
||||
{
|
||||
return edit_mode_;
|
||||
}
|
||||
|
||||
|
||||
void SetEditMode(EditMode m)
|
||||
{
|
||||
edit_mode_ = m;
|
||||
}
|
||||
|
||||
|
||||
void ToggleEditMode()
|
||||
{
|
||||
edit_mode_ = (edit_mode_ == EditMode::Code)
|
||||
? EditMode::Writing
|
||||
: EditMode::Code;
|
||||
}
|
||||
|
||||
|
||||
void SetSyntaxEnabled(bool on)
|
||||
{
|
||||
syntax_enabled_ = on;
|
||||
@@ -614,6 +658,9 @@ private:
|
||||
std::unique_ptr<struct UndoTree> undo_tree_;
|
||||
std::unique_ptr<UndoSystem> undo_sys_;
|
||||
|
||||
// Edit mode (code vs writing)
|
||||
EditMode edit_mode_ = EditMode::Code;
|
||||
|
||||
// Syntax/highlighting state
|
||||
std::uint64_t version_ = 0; // increment on edits
|
||||
bool syntax_enabled_ = true;
|
||||
|
||||
Reference in New Issue
Block a user