One place to pick a buffer's highlighter
Filetype detection (extension or shebang) was written out three times (two open paths in Editor and the ImGui frontend's per-frame check) and "highlighter for this filetype, else the null one" five times (Buffer's copy constructor and assignment, Editor::SwitchTo, :set filetype). Buffer::ApplyDetectedFiletype and InstallFiletypeHighlighter replace them. The InvalidateFrom(0) calls after SetHighlighter are dropped: SetHighlighter already clears the caches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
+2
-18
@@ -19,8 +19,6 @@
|
||||
#include "fonts/Font.h" // embedded default font (DefaultFont)
|
||||
#include "fonts/FontRegistry.h"
|
||||
#include "fonts/IosevkaExtended.h"
|
||||
#include "syntax/HighlighterRegistry.h"
|
||||
#include "syntax/NullHighlighter.h"
|
||||
|
||||
|
||||
#ifndef KTE_FONT_SIZE
|
||||
@@ -54,22 +52,8 @@ apply_syntax_to_buffer(Buffer *b, const GUIConfig &cfg)
|
||||
if (cfg.syntax && b->GetEditMode() != EditMode::Writing) {
|
||||
b->SetSyntaxEnabled(true);
|
||||
b->EnsureHighlighter();
|
||||
if (auto *eng = b->Highlighter()) {
|
||||
if (!eng->HasHighlighter()) {
|
||||
const std::string first_line = b->Nrows() > 0 ? b->GetLineString(0) : std::string();
|
||||
std::string ft = kte::HighlighterRegistry::DetectForPath(
|
||||
b->Filename(), first_line);
|
||||
if (!ft.empty()) {
|
||||
eng->SetHighlighter(kte::HighlighterRegistry::CreateFor(ft));
|
||||
b->SetFiletype(ft);
|
||||
eng->InvalidateFrom(0);
|
||||
} else {
|
||||
eng->SetHighlighter(std::make_unique<kte::NullHighlighter>());
|
||||
b->SetFiletype("");
|
||||
eng->InvalidateFrom(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!b->Highlighter()->HasHighlighter())
|
||||
b->ApplyDetectedFiletype();
|
||||
} else {
|
||||
b->SetSyntaxEnabled(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user