Highlighters does not need to inherit from HighlighterGroup
Just compose, to avoid coupling Highlighters with the Highlighter interface. And yeah, that naming is a bit confusing.
This commit is contained in:
parent
6272847ace
commit
94a0c9bb45
|
@ -653,7 +653,7 @@ Completions highlighter_cmd_completer(
|
|||
if (scope == "shared")
|
||||
root = &DefinedHighlighters::instance();
|
||||
else if (auto* s = get_scope_ifp(scope, context))
|
||||
root = &s->highlighters();
|
||||
root = &s->highlighters().group();
|
||||
else
|
||||
return {};
|
||||
|
||||
|
@ -676,8 +676,8 @@ Highlighter& get_highlighter(const Context& context, StringView path)
|
|||
|
||||
auto sep_it = find(path, '/');
|
||||
StringView scope{path.begin(), sep_it};
|
||||
auto* root = (scope == "shared") ? (HighlighterGroup*)&DefinedHighlighters::instance()
|
||||
: (HighlighterGroup*)&get_scope(scope, context).highlighters();
|
||||
auto* root = (scope == "shared") ? static_cast<HighlighterGroup*>(&DefinedHighlighters::instance())
|
||||
: static_cast<HighlighterGroup*>(&get_scope(scope, context).highlighters().group());
|
||||
if (sep_it != path.end())
|
||||
return root->get_child(StringView{sep_it+1, path.end()});
|
||||
return *root;
|
||||
|
|
|
@ -69,19 +69,19 @@ Completions HighlighterGroup::complete_child(StringView path, ByteCount cursor_p
|
|||
return { 0, 0, std::move(candidates) };
|
||||
}
|
||||
|
||||
void Highlighters::do_highlight(const Context& context, HighlightPass pass,
|
||||
void Highlighters::highlight(const Context& context, HighlightPass pass,
|
||||
DisplayBuffer& display_buffer, BufferRange range)
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->do_highlight(context, pass, display_buffer, range);
|
||||
HighlighterGroup::do_highlight(context, pass, display_buffer, range);
|
||||
m_parent->highlight(context, pass, display_buffer, range);
|
||||
m_group.highlight(context, pass, display_buffer, range);
|
||||
}
|
||||
|
||||
void Highlighters::do_compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup)
|
||||
void Highlighters::compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup)
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->do_compute_display_setup(context, pass, setup);
|
||||
HighlighterGroup::do_compute_display_setup(context, pass, setup);
|
||||
m_parent->compute_display_setup(context, pass, setup);
|
||||
m_group.compute_display_setup(context, pass, setup);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,19 +36,25 @@ protected:
|
|||
HighlighterMap m_highlighters;
|
||||
};
|
||||
|
||||
class Highlighters : public HighlighterGroup, public SafeCountable
|
||||
struct ScopeList;
|
||||
|
||||
class Highlighters : public SafeCountable
|
||||
{
|
||||
public:
|
||||
Highlighters(Highlighters& parent) : HighlighterGroup{HighlightPass::All}, SafeCountable{}, m_parent(&parent) {}
|
||||
Highlighters(Highlighters& parent) : SafeCountable{}, m_parent{&parent}, m_group{HighlightPass::All} {}
|
||||
|
||||
HighlighterGroup& group() { return m_group; }
|
||||
const HighlighterGroup& group() const { return m_group; }
|
||||
|
||||
void highlight(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range);
|
||||
void compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup);
|
||||
|
||||
private:
|
||||
void do_highlight(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range) override;
|
||||
void do_compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup) override;
|
||||
|
||||
friend class Scope;
|
||||
Highlighters() : HighlighterGroup{HighlightPass::All} {}
|
||||
Highlighters() : m_group{HighlightPass::All} {}
|
||||
|
||||
SafePtr<Highlighters> m_parent;
|
||||
HighlighterGroup m_group;
|
||||
};
|
||||
|
||||
struct DefinedHighlighters : public HighlighterGroup,
|
||||
|
|
|
@ -28,7 +28,7 @@ Window::Window(Buffer& buffer)
|
|||
|
||||
options().register_watcher(*this);
|
||||
|
||||
setup_builtin_highlighters(m_builtin_highlighters);
|
||||
setup_builtin_highlighters(m_builtin_highlighters.group());
|
||||
|
||||
for (auto& option : options().flatten_options())
|
||||
on_option_changed(*option);
|
||||
|
|
Loading…
Reference in New Issue
Block a user