Add a Window::display_position(const BufferIterator&) method

This commit is contained in:
Maxime Coste 2012-09-30 16:22:03 +02:00
parent 6cd5d80757
commit 801e3eaae2
2 changed files with 26 additions and 0 deletions

View File

@ -129,6 +129,30 @@ void Window::scroll_to_keep_cursor_visible_ifn()
} }
} }
DisplayCoord Window::display_position(const BufferIterator& iterator)
{
DisplayCoord res{0,0};
for (auto& line : m_display_buffer.lines())
{
if (line.buffer_line() == iterator.line())
{
for (auto& atom : line)
{
auto& content = atom.content;
if (content.has_buffer_range() and
iterator >= content.begin() and iterator < content.end())
{
res.column += iterator - content.begin();
return res;
}
res.column += content.length();
}
}
++res.line;
}
return { 0, 0 };
}
String Window::status_line() const String Window::status_line() const
{ {
BufferCoord cursor = buffer().line_and_column_at(selections().back().last()); BufferCoord cursor = buffer().line_and_column_at(selections().back().last());

View File

@ -35,6 +35,8 @@ public:
void center_selection(); void center_selection();
void update_display_buffer(); void update_display_buffer();
DisplayCoord display_position(const BufferIterator& it);
String status_line() const; String status_line() const;
HighlighterGroup& highlighters() { return m_highlighters; } HighlighterGroup& highlighters() { return m_highlighters; }