begin using BufferView class to control the BufferPane layout

This commit is contained in:
Josh Holtrop 2017-09-20 19:34:57 -04:00
parent 382552d25c
commit 22171cacf9
4 changed files with 153 additions and 522 deletions

View File

@ -1,11 +1,30 @@
#include "BufferPane.h"
int BufferPane::Cwd::operator()(uint32_t character)
{
if (character < 0x20u)
{
return 2;
}
else if (character < 0x80u)
{
return 1;
}
else
{
return std::max(1, m_window->font()->get_glyph(character)->get_advance() / m_window->font()->get_advance());
}
}
BufferPane::BufferPane(Window * window, std::shared_ptr<Buffer> buffer)
: m_window(window), m_buffer(buffer)
: m_window(window), m_buffer(buffer), m_cwd(window)
{
m_cursor_screen_row = 0;
m_scroll_offset = 5;
m_iterator = buffer->add_cursor();
m_buffer_view = std::make_shared<BufferView>(buffer, m_iterator, m_cwd);
m_buffer_view->set_scroll_offset(5);
m_buffer_view->update();
m_target_column = 0;
m_cursor_virtual_column = 0;
m_show_status_bar = true;
@ -23,275 +42,19 @@ void BufferPane::resize(int width, int height)
height_subtract = m_window->font()->get_line_height() + 1;
}
m_rows = std::max(1, (m_height - height_subtract) / m_window->font()->get_line_height());
}
void BufferPane::walk_line(const Buffer::Iterator & start_of_line, std::function<void(int, int, int, int, const Buffer::Iterator &)> callback)
{
int row_offset = 0;
int screen_column = 0;
int virtual_column = 0;
Buffer::Iterator i = start_of_line;
for (;;)
{
uint32_t code_point = *i;
if ((code_point == '\n') || (!i.valid()))
{
callback(row_offset, screen_column, virtual_column, 0, i);
break;
}
int c_width;
if (code_point == '\t')
{
uint8_t tabstop = m_buffer->tabstop();
c_width = tabstop - virtual_column % tabstop;
}
else
{
c_width = character_width(code_point);
if (((screen_column + c_width) > m_columns) &&
(screen_column > 0))
{
row_offset++;
screen_column = 0;
}
}
callback(row_offset, screen_column, virtual_column, c_width, i);
virtual_column += c_width;
if (code_point == '\t')
{
screen_column += c_width;
while (screen_column >= m_columns)
{
screen_column -= m_columns;
row_offset++;
}
}
else
{
if ((screen_column + c_width) >= m_columns)
{
row_offset++;
screen_column = 0;
}
else
{
screen_column += c_width;
}
}
i.go_forward();
}
}
int BufferPane::calculate_rows_in_line(const Buffer::Iterator & start_of_line)
{
int saved_row_offset = 0;
walk_line(start_of_line, [this, &saved_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
uint32_t code_point = *i;
if (m_command_mode ||
((code_point != '\n') &&
(code_point != Buffer::Iterator::INVALID_CODE_POINT)))
{
saved_row_offset = row_offset;
}
});
return saved_row_offset + 1;
}
int BufferPane::calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line)
{
int saved_row_offset = 0;
walk_line(start_of_line, [this, &saved_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
uint32_t code_point = *i;
if (i == *m_iterator)
{
m_cursor_virtual_column = virtual_column;
m_cursor_screen_column = screen_column;
m_cursor_row_offset = row_offset;
}
if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT))
{
saved_row_offset = row_offset;
}
});
return saved_row_offset + 1;
}
int BufferPane::calculate_rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset)
{
int saved_row_offset = 0;
walk_line(start_of_line, [this, &saved_row_offset, &reference, &iterator_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
uint32_t code_point = *i;
if (i == reference)
{
*iterator_row_offset = row_offset;
}
if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT))
{
saved_row_offset = row_offset;
}
});
return saved_row_offset + 1;
}
int BufferPane::screen_rows_below_line(const Buffer::Iterator & line)
{
Buffer::Iterator i = line;
int rows = 0;
while ((rows < m_rows) && i.go_next_line())
{
rows += calculate_rows_in_line(i);
}
return rows;
}
int BufferPane::screen_rows_above_line(const Buffer::Iterator & line, std::list<std::pair<int, Buffer::Iterator>> & backward_lines)
{
Buffer::Iterator i = line;
int rows = 0;
while ((rows < m_rows) && i.go_previous_line())
{
int rows_in_this_line = calculate_rows_in_line(i);
rows += rows_in_this_line;
backward_lines.push_back(std::pair<int, Buffer::Iterator>(rows_in_this_line, i));
}
return rows;
}
void BufferPane::update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> & backward_lines)
{
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
int rows_in_cursor_line = calculate_rows_in_cursor_line(start_of_line);
int so = effective_scroll_offset();
int rows_above = screen_rows_above_line(*m_iterator, backward_lines) + m_cursor_row_offset;
int rows_below = screen_rows_below_line(*m_iterator) + std::max(0, rows_in_cursor_line - m_cursor_row_offset - 1);
int min_rows_to_leave_above = std::min(rows_above, so);
int min_rows_to_leave_below = std::min(rows_below, so);
m_cursor_screen_row = std::min(m_rows - min_rows_to_leave_below - 1, m_cursor_screen_row);
m_cursor_screen_row = std::max(min_rows_to_leave_above, m_cursor_screen_row);
m_cursor_screen_row = std::max(m_rows - rows_below - 1, m_cursor_screen_row);
m_cursor_screen_row = std::min(rows_above, m_cursor_screen_row);
}
bool BufferPane::move_cursor_screen_row_up()
{
size_t previous_iterator_offset = m_iterator->offset();
if (m_cursor_row_offset > 0)
{
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
walk_line(start_of_line, [this](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
if (((*i != '\n') || insert_mode()) &&
(screen_column <= m_cursor_screen_column) &&
(row_offset < m_cursor_row_offset))
{
*m_iterator = i;
}
});
}
else
{
if (!m_iterator->go_previous_line())
{
return false;
}
walk_line(*m_iterator, [this](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
if (((*i != '\n') || insert_mode()) &&
(screen_column <= m_cursor_screen_column))
{
*m_iterator = i;
}
});
}
return m_iterator->offset() != previous_iterator_offset;
}
bool BufferPane::move_cursor_screen_row_down()
{
size_t previous_iterator_offset = m_iterator->offset();
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
walk_line(start_of_line, [this](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
if (((*i != '\n') || insert_mode()) &&
(screen_column <= m_cursor_screen_column) &&
(row_offset > m_cursor_row_offset))
{
*m_iterator = i;
}
});
if (m_iterator->offset() != previous_iterator_offset)
{
return true;
}
if (!m_iterator->go_next_line())
{
return false;
}
walk_line(*m_iterator, [this](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
if (((*i != '\n') || insert_mode()) &&
(screen_column <= m_cursor_screen_column) &&
(row_offset == 0))
{
*m_iterator = i;
}
});
return m_iterator->offset() != previous_iterator_offset;
}
int BufferPane::determine_new_cursor_screen_row()
{
if (m_screen_lines.size() > 0)
{
if (m_iterator->line() < m_screen_lines.begin()->second.line())
{
return 0;
}
if (m_iterator->line() > m_screen_lines.rbegin()->second.line())
{
return m_rows;
}
for (auto screen_line : m_screen_lines)
{
if (screen_line.second.line() == m_iterator->line())
{
calculate_rows_in_cursor_line(screen_line.second);
return screen_line.first + m_cursor_row_offset;
}
}
}
return 0;
m_buffer_view->resize(m_columns, m_rows);
m_buffer_view->update();
}
void BufferPane::draw()
{
m_screen_lines.clear();
if (m_iterator->valid())
{
std::list<std::pair<int, Buffer::Iterator>> backward_lines;
update_cursor_row(backward_lines);
int screen_row = m_cursor_screen_row - m_cursor_row_offset;
Buffer::Iterator i = *m_iterator;
if (screen_row <= 0)
for (auto line_iterator = m_buffer_view->vert_iter();
line_iterator.is_valid();
line_iterator++)
{
i.go_start_of_line();
}
else for (auto rows_iterator_pair : backward_lines)
{
screen_row -= rows_iterator_pair.first;
i = rows_iterator_pair.second;
if (screen_row <= 0)
{
break;
}
}
while (screen_row <= m_rows)
{
m_screen_lines.push_back(std::pair<int, Buffer::Iterator>(screen_row, i));
screen_row += draw_buffer_line(screen_row, i);
if (!i.go_next_line())
{
break;
}
draw_buffer_line(line_iterator.row_offset(), line_iterator.iterator());
}
}
else
@ -304,78 +67,85 @@ void BufferPane::draw()
}
}
int BufferPane::draw_buffer_line(int screen_row, const Buffer::Iterator & start_of_line)
void BufferPane::scroll_window_up(Window::ScrollMode scroll_mode)
{
int lines_to_scroll = calculate_lines_to_scroll(scroll_mode);
m_buffer_view->scroll_view_up(lines_to_scroll, insert_mode());
m_buffer_view->update();
m_window->request_redraw();
}
void BufferPane::scroll_window_down(Window::ScrollMode scroll_mode)
{
int lines_to_scroll = calculate_lines_to_scroll(scroll_mode);
m_buffer_view->scroll_view_down(lines_to_scroll, insert_mode());
m_buffer_view->update();
m_window->request_redraw();
}
void BufferPane::draw_buffer_line(int screen_row, std::shared_ptr<Buffer::Iterator> start_of_line)
{
int saved_row_offset = 0;
int last_drawn_crosshair_row = -1;
walk_line(start_of_line, [this, &saved_row_offset, &screen_row, &last_drawn_crosshair_row](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
uint32_t code_point = *i;
int draw_row = screen_row + row_offset;
if ((draw_row >= 0) && (draw_row <= m_rows))
for (auto it = m_buffer_view->horiz_iter(start_of_line);
it.is_valid();
it++)
{
int draw_row = screen_row + it.row_offset();
int cwidth = std::max(it.character_width(), 1);
if ((draw_row < 0) || (draw_row > m_rows))
continue;
if (it.iterator()->line() == m_iterator->line())
{
if (i.line() == m_iterator->line())
if ((draw_row > last_drawn_crosshair_row) &&
((!it.is_eol()) || (it.row_offset() == 0)))
{
if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT))
{
if (draw_row > last_drawn_crosshair_row)
{
for (int col = screen_column; col < m_columns; col++)
{
draw_crosshair(col_x(col), row_y(draw_row));
}
last_drawn_crosshair_row = draw_row;
}
}
}
else if ((m_cursor_virtual_column >= virtual_column) &&
(m_cursor_virtual_column < (virtual_column + std::max(character_width, 1))))
{
int col = screen_column + (m_cursor_virtual_column - virtual_column);
int row = draw_row;
while (screen_column >= m_columns)
{
screen_column -= m_columns;
row++;
}
draw_crosshair(col_x(col), row_y(row));
}
if (i == *m_iterator)
{
bool wrap = (code_point == '\t');
int row = draw_row;
int col = screen_column;
int w = std::max(1, character_width);
for (int i = 0; i < w; i++)
{
draw_cursor(col_x(col), row_y(row), i, w);
col++;
if (wrap && (col >= m_columns))
{
row++;
col = 0;
}
}
}
if ((code_point == '\n') || (code_point == Buffer::Iterator::INVALID_CODE_POINT))
{
if ((m_cursor_virtual_column > virtual_column) &&
(m_cursor_virtual_column < (virtual_column + (m_columns - screen_column))))
{
draw_crosshair(col_x(screen_column + (m_cursor_virtual_column - virtual_column)),
row_y(draw_row));
}
}
else
{
draw_character(code_point, draw_row, screen_column);
}
if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT))
{
saved_row_offset = row_offset;
draw_crosshair(0, row_y(draw_row), col_x(m_columns));
last_drawn_crosshair_row = draw_row;
}
}
});
return saved_row_offset + 1;
else if ((m_cursor_virtual_column >= it.virtual_column()) &&
(m_cursor_virtual_column < (it.virtual_column() + cwidth)))
{
int col = it.screen_column() + (m_cursor_virtual_column - it.virtual_column());
int row = draw_row;
while (col >= m_columns)
{
col -= m_columns;
row++;
}
draw_crosshair(col_x(col), row_y(row));
}
if (*it.iterator() == *m_iterator)
{
bool wrap = (it.code_point() == '\t');
int row = draw_row;
int col = it.screen_column();
for (int i = 0; i < cwidth; i++)
{
draw_cursor(col_x(col), row_y(row), i, cwidth);
col++;
if (wrap && (col >= m_columns))
{
row++;
col = 0;
}
}
}
if (it.is_eol())
{
if ((m_cursor_virtual_column > it.virtual_column()) &&
(m_cursor_virtual_column < (it.virtual_column() + (m_columns - it.screen_column()))))
{
draw_crosshair(col_x(it.screen_column() + (m_cursor_virtual_column - it.virtual_column())),
row_y(draw_row));
}
}
else
{
draw_character(it.code_point(), draw_row, it.screen_column());
}
}
}
void BufferPane::draw_character(uint32_t character, int screen_row, int screen_column)
@ -402,22 +172,6 @@ void BufferPane::draw_character(uint32_t character, int screen_row, int screen_c
}
}
int BufferPane::character_width(uint32_t character)
{
if (character < 0x20u)
{
return 2;
}
else if (character < 0x80u)
{
return 1u;
}
else
{
return std::max(1, m_window->font()->get_glyph(character)->get_advance() / m_window->font()->get_advance());
}
}
void BufferPane::draw_cursor(int x, int y, int i, int columns)
{
if (m_command_mode && (!m_focused))
@ -452,12 +206,14 @@ void BufferPane::draw_cursor(int x, int y, int i, int columns)
}
}
void BufferPane::draw_crosshair(int x, int y)
void BufferPane::draw_crosshair(int x, int y, int width, int height)
{
if (!m_command_mode)
{
int width = m_window->font()->get_advance();
int height = m_window->font()->get_line_height();
if (width < 0)
width = m_window->font()->get_advance();
if (height < 0)
height = m_window->font()->get_line_height();
m_window->gl()->draw_rect(win_x(x), win_y(y), width, height, 0.1, 0.1, 0.1, 1.0);
}
}
@ -471,6 +227,7 @@ void BufferPane::exit_insert_mode()
{
m_iterator->go_back();
}
m_buffer_view->update();
m_window->request_redraw();
}
}
@ -500,6 +257,7 @@ void BufferPane::insert_code_point(uint32_t code_point)
}
m_buffer->insert_code_point(*m_iterator, code_point);
}
m_buffer_view->update();
m_window->request_redraw();
}
}
@ -513,6 +271,7 @@ void BufferPane::kill_character_at_cursor()
{
m_iterator->go_left_in_line();
}
m_buffer_view->update();
m_window->request_redraw();
}
}
@ -534,92 +293,12 @@ size_t BufferPane::display_column() const
return m_cursor_virtual_column + 1u;
}
void BufferPane::cursor_move(Window::CursorMovement which)
void BufferPane::cursor_move(BufferPane::CursorMovement which)
{
bool moved = false;
switch (which)
{
case Window::CursorMovement::LEFT:
moved = m_iterator->go_left_in_line();
break;
case Window::CursorMovement::RIGHT:
moved = m_iterator->go_right_in_line(insert_mode());
break;
case Window::CursorMovement::UP:
moved = m_iterator->go_previous_line();
break;
case Window::CursorMovement::DOWN:
moved = m_iterator->go_next_line();
break;
case Window::CursorMovement::SOL:
moved = m_iterator->go_start_of_line();
break;
case Window::CursorMovement::EOL:
moved = m_iterator->go_end_of_line(insert_mode());
break;
case Window::CursorMovement::FIRST_LINE:
{
auto it = m_buffer->begin();
if (it != *m_iterator)
{
*m_iterator = it;
moved = true;
}
}
break;
case Window::CursorMovement::LAST_LINE:
{
auto it = m_buffer->end();
it.go_back();
it.go_start_of_line();
if (it != *m_iterator)
{
*m_iterator = it;
moved = true;
}
}
break;
case Window::CursorMovement::SCREEN_ROW_UP:
moved = move_cursor_screen_row_up();
break;
case Window::CursorMovement::SCREEN_ROW_DOWN:
moved = move_cursor_screen_row_down();
break;
}
bool moved = m_buffer_view->cursor_move(which, insert_mode());
if (moved)
{
switch (which)
{
case Window::CursorMovement::LEFT:
case Window::CursorMovement::RIGHT:
{
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
calculate_rows_in_cursor_line(start_of_line);
m_target_column = m_cursor_virtual_column;
}
break;
case Window::CursorMovement::UP:
forward_to_column(m_target_column, insert_mode());
break;
case Window::CursorMovement::DOWN:
forward_to_column(m_target_column, insert_mode());
break;
case Window::CursorMovement::SOL:
m_target_column = 0;
break;
case Window::CursorMovement::EOL:
m_target_column = INT_MAX;
break;
case Window::CursorMovement::FIRST_LINE:
m_cursor_screen_row = 0;
break;
case Window::CursorMovement::LAST_LINE:
m_cursor_screen_row = m_rows;
break;
}
m_cursor_screen_row = determine_new_cursor_screen_row();
m_buffer_view->update();
m_window->request_redraw();
}
}
@ -654,7 +333,7 @@ void BufferPane::enter_insert_mode(Window::EnterInsertModeMode which)
m_buffer->enter_insert_mode();
m_buffer->insert_code_point(*m_iterator, '\n');
m_buffer->exit_insert_mode();
cursor_move(Window::CursorMovement::UP);
cursor_move(CursorMovement::UP);
enter_insert_mode(Window::EnterInsertModeMode::START_OF_CHAR);
break;
case Window::EnterInsertModeMode::NEW_LINE_AFTER:
@ -664,6 +343,7 @@ void BufferPane::enter_insert_mode(Window::EnterInsertModeMode which)
break;
}
m_buffer_view->update();
m_window->request_redraw();
}
@ -687,48 +367,6 @@ int BufferPane::calculate_lines_to_scroll(Window::ScrollMode scroll_mode)
return 0;
}
void BufferPane::scroll_window_up(Window::ScrollMode scroll_mode)
{
int lines_to_scroll = calculate_lines_to_scroll(scroll_mode);
int so = effective_scroll_offset();
int lines_to_move_cursor = (so + lines_to_scroll) - (m_rows - m_cursor_screen_row - 1);
while (lines_to_move_cursor-- > 0)
{
move_cursor_screen_row_up();
}
m_cursor_screen_row += lines_to_scroll;
m_window->request_redraw();
}
void BufferPane::scroll_window_down(Window::ScrollMode scroll_mode)
{
int lines_to_scroll = calculate_lines_to_scroll(scroll_mode);
int so = effective_scroll_offset();
int lines_to_move_cursor = (so + lines_to_scroll) - m_cursor_screen_row;
while (lines_to_move_cursor-- > 0)
{
move_cursor_screen_row_down();
}
m_cursor_screen_row -= lines_to_scroll;
m_window->request_redraw();
}
void BufferPane::forward_to_column(int column, bool allow_eol)
{
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
walk_line(start_of_line, [this, &column, &allow_eol](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) {
uint32_t code_point = *i;
if ((code_point != '\n') || allow_eol)
{
if (virtual_column <= column)
{
*m_iterator = i;
}
}
});
}
void BufferPane::draw_status_bar()
{
m_window->gl()->draw_rect(win_x(0), win_y(m_window->font()->get_line_height()), m_width, 1, 0.5, 0.5, 0.5, 1.0);
@ -755,12 +393,14 @@ void BufferPane::draw_status_bar()
void BufferPane::undo()
{
m_buffer->undo();
m_buffer_view->update();
m_window->request_redraw();
}
void BufferPane::redo()
{
m_buffer->redo();
m_buffer_view->update();
m_window->request_redraw();
}
@ -775,4 +415,5 @@ void BufferPane::clear()
{
m_buffer->clear();
*m_iterator = m_buffer->begin();
m_buffer_view->update();
}

View File

@ -7,14 +7,31 @@
#include "GL.h"
#include <memory>
#include "Window.h"
#include "CharacterWidthDeterminer.h"
#include "BufferView.h"
class BufferPane : public Pane
{
public:
class Cwd : public CharacterWidthDeterminer
{
public:
Cwd(Window * window)
{
m_window = window;
}
int operator()(uint32_t character);
protected:
Window * m_window;
};
typedef BufferView::CursorMovement CursorMovement;
BufferPane(Window * window, std::shared_ptr<Buffer> buffer);
void resize(int width, int height) override;
void draw();
void cursor_move(Window::CursorMovement which);
void cursor_move(CursorMovement which);
void enter_insert_mode(Window::EnterInsertModeMode which);
void insert_code_point(uint32_t code_point);
void exit_insert_mode();
@ -34,28 +51,13 @@ public:
m_focused = focused;
}
void clear();
int calculate_rows_in_line(const Buffer::Iterator & start_of_line);
std::shared_ptr<Buffer> buffer() const { return m_buffer; }
protected:
int effective_scroll_offset()
{
return std::min(m_scroll_offset, (m_rows - 1) / 2);
}
int draw_buffer_line(int screen_row, const Buffer::Iterator & start_of_line);
void draw_buffer_line(int screen_row, std::shared_ptr<Buffer::Iterator> start_of_line);
void draw_character(uint32_t character, int screen_row, int screen_column);
int character_width(uint32_t character);
void draw_cursor(int x, int y, int i, int columns);
void draw_crosshair(int x, int y);
int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line);
int calculate_rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset);
int screen_rows_below_line(const Buffer::Iterator & line);
int screen_rows_above_line(const Buffer::Iterator & line, std::list<std::pair<int, Buffer::Iterator>> & backward_lines);
void update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> & backward_lines);
bool move_cursor_screen_row_up();
bool move_cursor_screen_row_down();
void walk_line(const Buffer::Iterator & start_of_line, std::function<void(int, int, int, int, const Buffer::Iterator &)> callback);
int determine_new_cursor_screen_row();
void draw_crosshair(int x, int y, int width = -1, int height = -1);
int col_x(int col)
{
return col * m_window->font()->get_advance();
@ -64,7 +66,6 @@ protected:
{
return m_height - (row + 1) * m_window->font()->get_line_height();
}
void forward_to_column(int column, bool allow_eol);
size_t display_line() const { return m_iterator->line() + 1u; }
size_t display_column() const;
void draw_status_bar();
@ -72,6 +73,8 @@ protected:
Window * m_window;
std::shared_ptr<Buffer> m_buffer;
Cwd m_cwd;
std::shared_ptr<BufferView> m_buffer_view;
int m_rows;
int m_columns;
int m_scroll_offset;

View File

@ -280,22 +280,22 @@ void Window::handle_keyval(uint32_t keyval)
switch (keyval)
{
case SDLK_HOME:
m_focused_buffer_pane->cursor_move(CursorMovement::SOL);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::SOL);
break;
case SDLK_END:
m_focused_buffer_pane->cursor_move(CursorMovement::EOL);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::EOL);
break;
case SDLK_RIGHT:
m_focused_buffer_pane->cursor_move(CursorMovement::RIGHT);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::RIGHT);
break;
case SDLK_LEFT:
m_focused_buffer_pane->cursor_move(CursorMovement::LEFT);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::LEFT);
break;
case SDLK_DOWN:
m_focused_buffer_pane->cursor_move(CursorMovement::DOWN);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::DOWN);
break;
case SDLK_UP:
m_focused_buffer_pane->cursor_move(CursorMovement::UP);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::UP);
break;
case SDLK_PAGEUP:
m_focused_buffer_pane->scroll_window_up(ScrollMode::WHOLE_SCREEN);
@ -340,10 +340,10 @@ void Window::handle_keyval(uint32_t keyval)
switch (keyval)
{
case '0':
m_focused_buffer_pane->cursor_move(CursorMovement::SOL);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::SOL);
break;
case '$':
m_focused_buffer_pane->cursor_move(CursorMovement::EOL);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::EOL);
break;
case ':':
m_command_buffer_pane->clear();
@ -353,7 +353,7 @@ void Window::handle_keyval(uint32_t keyval)
m_focused_buffer_pane->enter_insert_mode(EnterInsertModeMode::END_OF_LINE);
break;
case 'G':
m_focused_buffer_pane->cursor_move(CursorMovement::LAST_LINE);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::LAST_LINE);
break;
case 'I':
m_focused_buffer_pane->enter_insert_mode(EnterInsertModeMode::START_OF_LINE);
@ -365,22 +365,22 @@ void Window::handle_keyval(uint32_t keyval)
m_focused_buffer_pane->enter_insert_mode(EnterInsertModeMode::END_OF_CHAR);
break;
case 'g':
m_focused_buffer_pane->cursor_move(CursorMovement::FIRST_LINE);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::FIRST_LINE);
break;
case 'h':
m_focused_buffer_pane->cursor_move(CursorMovement::LEFT);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::LEFT);
break;
case 'i':
m_focused_buffer_pane->enter_insert_mode(EnterInsertModeMode::START_OF_CHAR);
break;
case 'j':
m_focused_buffer_pane->cursor_move(CursorMovement::DOWN);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::DOWN);
break;
case 'k':
m_focused_buffer_pane->cursor_move(CursorMovement::UP);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::UP);
break;
case 'l':
m_focused_buffer_pane->cursor_move(CursorMovement::RIGHT);
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::RIGHT);
break;
case 'o':
m_focused_buffer_pane->enter_insert_mode(EnterInsertModeMode::NEW_LINE_AFTER);
@ -433,7 +433,8 @@ void Window::resize()
void Window::redraw()
{
static int last_command_buffer_screen_rows = 0;
m_command_buffer_screen_rows = std::min(5, m_command_buffer_pane->calculate_rows_in_line(m_command_buffer->begin()));
/* TODO: figure out number of command buffer screen rows. */
m_command_buffer_screen_rows = 1;
if (m_command_buffer_screen_rows != last_command_buffer_screen_rows)
{
resize();

View File

@ -27,20 +27,6 @@ public:
};
};
enum class CursorMovement : uint8_t
{
LEFT,
RIGHT,
UP,
DOWN,
SOL,
EOL,
FIRST_LINE,
LAST_LINE,
SCREEN_ROW_UP,
SCREEN_ROW_DOWN,
};
enum class ScrollMode : uint8_t
{
ONE_LINE,