window: support scrolling
This commit is contained in:
parent
04c7ce8f01
commit
d5012c9379
|
@ -11,12 +11,14 @@ using namespace Kakoune;
|
|||
|
||||
void draw_window(Window& window)
|
||||
{
|
||||
window.update_display_buffer();
|
||||
|
||||
int max_x,max_y;
|
||||
getmaxyx(stdscr, max_y, max_x);
|
||||
max_y -= 1;
|
||||
|
||||
window.set_dimensions(LineAndColumn(max_y, max_x));
|
||||
window.update_display_buffer();
|
||||
|
||||
|
||||
LineAndColumn position;
|
||||
for (const DisplayAtom& atom : window.display_buffer())
|
||||
{
|
||||
|
|
|
@ -170,4 +170,29 @@ void Window::set_dimensions(const LineAndColumn& dimensions)
|
|||
m_dimensions = dimensions;
|
||||
}
|
||||
|
||||
void Window::scroll_to_keep_cursor_visible_ifn()
|
||||
{
|
||||
if (m_cursor.line < 0)
|
||||
{
|
||||
m_position.line = std::max(m_position.line + m_cursor.line, 0);
|
||||
m_cursor.line = 0;
|
||||
}
|
||||
else if (m_cursor.line >= m_dimensions.line)
|
||||
{
|
||||
m_position.line += m_cursor.line - (m_dimensions.line - 1);
|
||||
m_cursor.line = m_dimensions.line - 1;
|
||||
}
|
||||
|
||||
if (m_cursor.column < 0)
|
||||
{
|
||||
m_position.column = std::max(m_position.column + m_cursor.column, 0);
|
||||
m_cursor.column = 0;
|
||||
}
|
||||
else if (m_cursor.column >= m_dimensions.column)
|
||||
{
|
||||
m_position.column += m_cursor.column - (m_dimensions.column - 1);
|
||||
m_cursor.column = m_dimensions.column - 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
void update_display_buffer();
|
||||
|
||||
private:
|
||||
void scroll_to_keep_cursor_visible_ifn();
|
||||
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
LineAndColumn m_position;
|
||||
|
|
Loading…
Reference in New Issue
Block a user