Make Wrap highlighter only wrap on window width.

This commit is contained in:
Maxime Coste 2017-04-30 21:15:56 +01:00
parent 5ee21ec932
commit bd3ba77e96
3 changed files with 12 additions and 28 deletions

View File

@ -656,15 +656,13 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params)
struct WrapHighlighter : Highlighter
{
WrapHighlighter(String col_expr) : m_col_expr{std::move(col_expr)} {}
void highlight(const Context& context, HighlightPass pass,
DisplayBuffer& display_buffer, BufferRange) override
{
if (pass != HighlightPass::Wrap)
return;
ColumnCount column = get_wrap_column(context);
ColumnCount column = context.window().display_setup().window_range.column;
if (column < 0)
return;
@ -726,7 +724,7 @@ struct WrapHighlighter : Highlighter
if (pass != HighlightPass::Wrap)
return;
ColumnCount column = get_wrap_column(context);
ColumnCount column = context.window().display_setup().window_range.column;
if (column < 0)
return;
@ -784,28 +782,11 @@ struct WrapHighlighter : Highlighter
static HighlighterAndId create(HighlighterParameters params)
{
if (params.size() != 1)
if (params.size() != 0)
throw runtime_error("wrong parameter count");
return {"wrap_" + params[0], make_unique<WrapHighlighter>(params[0])};
return {"wrap", make_unique<WrapHighlighter>()};
}
private:
ColumnCount get_wrap_column(const Context& context)
{
try
{
return {str_to_int_ifp(expand(m_col_expr, context)).value_or(0) - 1};
}
catch (runtime_error& err)
{
write_to_debug_buffer(
format("Error evaluating highlight column expression: {}", err.what()));
return {-1};
}
}
String m_col_expr;
};
void expand_tabulations(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange)

View File

@ -122,10 +122,10 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
return m_display_buffer;
kak_assert(&buffer() == &context.buffer());
auto setup = compute_display_setup(context);
m_position = setup.window_pos;
m_display_setup = compute_display_setup(context);
m_position = m_display_setup.window_pos;
for (LineCount line = 0; line < setup.window_range.line; ++line)
for (LineCount line = 0; line < m_display_setup.window_range.line; ++line)
{
LineCount buffer_line = m_position.line + line;
if (buffer_line >= buffer().line_count())
@ -206,9 +206,9 @@ DisplaySetup Window::compute_display_setup(const Context& context)
m_dimensions,
DisplayCoord{cursor.line - m_position.line, cursor_col - m_position.column}
};
for (auto pass : { HighlightPass::Wrap, HighlightPass::Move })
for (auto pass : { HighlightPass::Move, HighlightPass::Wrap })
m_highlighters.compute_display_setup(context, pass, offset, setup);
for (auto pass : { HighlightPass::Wrap, HighlightPass::Move })
for (auto pass : { HighlightPass::Move, HighlightPass::Wrap })
m_builtin_highlighters.compute_display_setup(context, pass, offset, setup);
return setup;

View File

@ -46,6 +46,8 @@ public:
void set_client(Client* client) { m_client = client; }
const DisplaySetup& display_setup() const { return m_display_setup; }
void clear_display_buffer();
private:
Window(const Window&) = delete;
@ -62,6 +64,7 @@ private:
DisplayCoord m_position;
DisplayCoord m_dimensions;
DisplayBuffer m_display_buffer;
DisplaySetup m_display_setup;
HighlighterGroup m_highlighters;
HighlighterGroup m_builtin_highlighters;