Make compute_display_setup methods const

This commit is contained in:
Maxime Coste 2018-04-06 09:12:17 +10:00
parent 21603983c5
commit 3c03129c46
6 changed files with 24 additions and 22 deletions

View File

@ -71,7 +71,7 @@ struct Highlighter
do_highlight(context, display_buffer, range); do_highlight(context, display_buffer, range);
} }
void compute_display_setup(HighlightContext context, DisplaySetup& setup) void compute_display_setup(HighlightContext context, DisplaySetup& setup) const
{ {
if (context.pass & m_passes) if (context.pass & m_passes)
do_compute_display_setup(context, setup); do_compute_display_setup(context, setup);
@ -89,7 +89,7 @@ struct Highlighter
private: private:
virtual void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) = 0; virtual void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) = 0;
virtual void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) {} virtual void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const {}
const HighlightPass m_passes; const HighlightPass m_passes;
}; };

View File

@ -12,7 +12,7 @@ void HighlighterGroup::do_highlight(HighlightContext context, DisplayBuffer& dis
hl.value->highlight(context, display_buffer, range); hl.value->highlight(context, display_buffer, range);
} }
void HighlighterGroup::do_compute_display_setup(HighlightContext context, DisplaySetup& setup) void HighlighterGroup::do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const
{ {
for (auto& hl : m_highlighters) for (auto& hl : m_highlighters)
hl.value->compute_display_setup(context, setup); hl.value->compute_display_setup(context, setup);
@ -84,7 +84,7 @@ void Highlighters::highlight(HighlightContext context, DisplayBuffer& display_bu
m_group.highlight(context, display_buffer, range); m_group.highlight(context, display_buffer, range);
} }
void Highlighters::compute_display_setup(HighlightContext context, DisplaySetup& setup) void Highlighters::compute_display_setup(HighlightContext context, DisplaySetup& setup) const
{ {
Vector<StringView> disabled_ids(context.disabled_ids.begin(), context.disabled_ids.end()); Vector<StringView> disabled_ids(context.disabled_ids.begin(), context.disabled_ids.end());
m_group.fill_unique_ids(disabled_ids); m_group.fill_unique_ids(disabled_ids);

View File

@ -32,7 +32,7 @@ public:
protected: protected:
void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) override; void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) override;
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override; void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override;
using HighlighterMap = HashMap<String, std::unique_ptr<Highlighter>, MemoryDomain::Highlight>; using HighlighterMap = HashMap<String, std::unique_ptr<Highlighter>, MemoryDomain::Highlight>;
HighlighterMap m_highlighters; HighlighterMap m_highlighters;
@ -47,7 +47,7 @@ public:
const HighlighterGroup& group() const { return m_group; } const HighlighterGroup& group() const { return m_group; }
void highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range); void highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range);
void compute_display_setup(HighlightContext context, DisplaySetup& setup); void compute_display_setup(HighlightContext context, DisplaySetup& setup) const;
private: private:
friend class Scope; friend class Scope;

View File

@ -727,7 +727,7 @@ struct WrapHighlighter : Highlighter
} }
} }
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override
{ {
if (contains(context.disabled_ids, ms_id)) if (contains(context.disabled_ids, ms_id))
return; return;
@ -817,7 +817,7 @@ struct WrapHighlighter : Highlighter
unique_ids.push_back(ms_id); unique_ids.push_back(ms_id);
} }
BufferCoord next_split_coord(const Buffer& buffer, ColumnCount wrap_column, int tabstop, BufferCoord coord) BufferCoord next_split_coord(const Buffer& buffer, ColumnCount wrap_column, int tabstop, BufferCoord coord) const
{ {
auto column = get_column(buffer, tabstop, coord); auto column = get_column(buffer, tabstop, coord);
auto col = get_byte_to_column( auto col = get_byte_to_column(
@ -913,7 +913,7 @@ struct TabulationHighlighter : Highlighter
} }
} }
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override
{ {
auto& buffer = context.context.buffer(); auto& buffer = context.context.buffer();
// Ensure that a cursor on a tab character makes the full tab character visible // Ensure that a cursor on a tab character makes the full tab character visible
@ -1069,7 +1069,7 @@ private:
} }
} }
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override
{ {
if (contains(context.disabled_ids, ms_id)) if (contains(context.disabled_ids, ms_id))
return; return;
@ -1083,7 +1083,7 @@ private:
unique_ids.push_back(ms_id); unique_ids.push_back(ms_id);
} }
int compute_digit_count(const Context& context) int compute_digit_count(const Context& context) const
{ {
int digit_count = 0; int digit_count = 0;
LineCount last_line = context.buffer().line_count(); LineCount last_line = context.buffer().line_count();
@ -1340,7 +1340,7 @@ private:
} }
} }
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override
{ {
auto& line_flags = context.context.options()[m_option_name].get_mutable<LineAndSpecList>(); auto& line_flags = context.context.options()[m_option_name].get_mutable<LineAndSpecList>();
auto& buffer = context.context.buffer(); auto& buffer = context.context.buffer();
@ -1597,7 +1597,7 @@ private:
{} {}
} }
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) override void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override
{ {
try try
{ {

View File

@ -179,8 +179,10 @@ void Window::set_dimensions(DisplayCoord dimensions)
} }
} }
DisplaySetup Window::compute_display_setup(const Context& context) DisplaySetup Window::compute_display_setup(const Context& context) const
{ {
auto win_pos = m_position;
DisplayCoord offset = options()["scrolloff"].get<DisplayCoord>(); DisplayCoord offset = options()["scrolloff"].get<DisplayCoord>();
offset.line = std::min(offset.line, (m_dimensions.line + 1) / 2); offset.line = std::min(offset.line, (m_dimensions.line + 1) / 2);
offset.column = std::min(offset.column, (m_dimensions.column + 1) / 2); offset.column = std::min(offset.column, (m_dimensions.column + 1) / 2);
@ -189,16 +191,16 @@ DisplaySetup Window::compute_display_setup(const Context& context)
const auto& cursor = context.selections().main().cursor(); const auto& cursor = context.selections().main().cursor();
// Ensure cursor line is visible // Ensure cursor line is visible
if (cursor.line - offset.line < m_position.line) if (cursor.line - offset.line < win_pos.line)
m_position.line = std::max(0_line, cursor.line - offset.line); win_pos.line = std::max(0_line, cursor.line - offset.line);
if (cursor.line + offset.line >= m_position.line + m_dimensions.line) if (cursor.line + offset.line >= win_pos.line + m_dimensions.line)
m_position.line = std::min(buffer().line_count()-1, cursor.line + offset.line - m_dimensions.line + 1); win_pos.line = std::min(buffer().line_count()-1, cursor.line + offset.line - m_dimensions.line + 1);
DisplaySetup setup{ DisplaySetup setup{
m_position, win_pos,
m_dimensions, m_dimensions,
{cursor.line - m_position.line, {cursor.line - win_pos.line,
get_column(buffer(), tabstop, cursor) - m_position.column}, get_column(buffer(), tabstop, cursor) - win_pos.column},
offset, offset,
false false
}; };

View File

@ -52,7 +52,7 @@ private:
Window(const Window&) = delete; Window(const Window&) = delete;
void on_option_changed(const Option& option) override; void on_option_changed(const Option& option) override;
DisplaySetup compute_display_setup(const Context& context); DisplaySetup compute_display_setup(const Context& context) const;
void run_hook_in_own_context(StringView hook_name, StringView param, void run_hook_in_own_context(StringView hook_name, StringView param,
String client_name = ""); String client_name = "");