Filters: add a show line numbers filter
This commit is contained in:
parent
2badb9d708
commit
316e84f119
|
@ -70,7 +70,7 @@ void expand_tabulations(DisplayBuffer& display_buffer)
|
|||
atom_it = display_buffer.split(atom_it, it+1);
|
||||
|
||||
BufferCoord pos = it.buffer().line_and_column_at(it);
|
||||
|
||||
|
||||
int column = 0;
|
||||
for (auto line_it = it.buffer().iterator_at({pos.line, 0});
|
||||
line_it != it; ++line_it)
|
||||
|
@ -90,4 +90,37 @@ void expand_tabulations(DisplayBuffer& display_buffer)
|
|||
}
|
||||
}
|
||||
|
||||
void show_line_numbers(DisplayBuffer& display_buffer)
|
||||
{
|
||||
const Buffer& buffer = display_buffer.front().begin().buffer();
|
||||
BufferCoord coord = buffer.line_and_column_at(display_buffer.begin()->begin());
|
||||
|
||||
int last_line = buffer.line_and_column_at(display_buffer.back().end()-1).line;
|
||||
|
||||
for (; coord.line <= last_line; ++coord.line)
|
||||
{
|
||||
BufferIterator line_start = buffer.iterator_at(coord);
|
||||
DisplayBuffer::iterator atom_it = display_buffer.atom_containing(line_start);
|
||||
if (atom_it != display_buffer.end())
|
||||
{
|
||||
if (atom_it->begin() != line_start)
|
||||
{
|
||||
if (not atom_it->splitable())
|
||||
continue;
|
||||
|
||||
atom_it = display_buffer.split(atom_it, line_start) + 1;
|
||||
}
|
||||
atom_it = display_buffer.insert(
|
||||
atom_it,
|
||||
DisplayAtom(atom_it->coord(),
|
||||
atom_it->begin(), atom_it->begin(),
|
||||
Color::Black, Color::White));
|
||||
|
||||
char buffer[6];
|
||||
snprintf(buffer, 6, "%3d ", coord.line);
|
||||
display_buffer.replace_atom_content(atom_it, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ void colorize_regex(DisplayBuffer& display_buffer,
|
|||
void colorize_cplusplus(DisplayBuffer& display_buffer);
|
||||
void colorize_cplusplus(DisplayBuffer& display_buffer);
|
||||
void expand_tabulations(DisplayBuffer& display_buffer);
|
||||
void show_line_numbers(DisplayBuffer& display_buffer);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ Window::Window(Buffer& buffer)
|
|||
m_filters.push_back(colorize_cplusplus);
|
||||
m_filters.push_back(expand_tabulations);
|
||||
m_filters.push_back(HighlightSelections(*this));
|
||||
m_filters.push_back(show_line_numbers);
|
||||
}
|
||||
|
||||
void Window::check_invariant() const
|
||||
|
|
Loading…
Reference in New Issue
Block a user