add 'A' and 'I' commands

This commit is contained in:
josh committed 2016-12-28 14:41:44 -05:00
1 parent 237dbf9c2b
commit dbe5843d77
2 files changed
+55 -8

No files matched your search

+44 -8
View File
@@ -333,16 +333,17 @@ void BufferPane::handle_key(uint32_t keyval)
case '$':
cursor_move(CursorMovement::EOL);
break;
case 'A':
enter_insert_mode(EnterInsertModeMode::END_OF_LINE);
break;
case 'G':
cursor_move(CursorMovement::LAST_LINE);
break;
case 'I':
enter_insert_mode(EnterInsertModeMode::START_OF_LINE);
break;
case 'a':
if (**m_iterator != '\n')
{
m_iterator->go_forward();
}
m_buffer->enter_insert_mode(*m_iterator);
m_window->request_redraw();
enter_insert_mode(EnterInsertModeMode::END_OF_CHAR);
break;
case 'g':
cursor_move(CursorMovement::FIRST_LINE);
@@ -351,8 +352,7 @@ void BufferPane::handle_key(uint32_t keyval)
cursor_move(CursorMovement::LEFT);
break;
case 'i':
m_buffer->enter_insert_mode(*m_iterator);
m_window->request_redraw();
enter_insert_mode(EnterInsertModeMode::START_OF_CHAR);
break;
case 'j':
cursor_move(CursorMovement::DOWN);
@@ -486,6 +486,42 @@ void BufferPane::cursor_move(CursorMovement which)
}
}
void BufferPane::enter_insert_mode(EnterInsertModeMode which)
{
if (m_buffer->insert_mode())
return;
switch (which)
{
case EnterInsertModeMode::START_OF_CHAR:
m_buffer->enter_insert_mode(*m_iterator);
break;
case EnterInsertModeMode::END_OF_CHAR:
if (**m_iterator != '\n')
{
m_iterator->go_forward();
}
m_buffer->enter_insert_mode(*m_iterator);
break;
case EnterInsertModeMode::START_OF_LINE:
m_iterator->go_start_of_line();
enter_insert_mode(EnterInsertModeMode::START_OF_CHAR);
break;
case EnterInsertModeMode::END_OF_LINE:
m_iterator->go_end_of_line(false);
enter_insert_mode(EnterInsertModeMode::END_OF_CHAR);
break;
case EnterInsertModeMode::NEW_LINE_BEFORE:
/* TODO */
break;
case EnterInsertModeMode::NEW_LINE_AFTER:
/* TODO */
break;
}
m_window->request_redraw();
}
void BufferPane::forward_to_column(int column, bool allow_eol)
{
Buffer::Iterator start_of_line = *m_iterator;
+11
View File
@@ -29,6 +29,16 @@ protected:
LAST_LINE,
};
enum class EnterInsertModeMode : uint8_t
{
START_OF_CHAR,
END_OF_CHAR,
START_OF_LINE,
END_OF_LINE,
NEW_LINE_BEFORE,
NEW_LINE_AFTER,
};
int effective_scroll_offset()
{
return std::min(m_scroll_offset, (m_rows - 1) / 2);
@@ -53,6 +63,7 @@ protected:
return m_height - (row + 1) * m_window->font()->get_line_height();
}
void cursor_move(CursorMovement which);
void enter_insert_mode(EnterInsertModeMode which);
void forward_to_column(int column, bool allow_eol);
size_t display_line() const { return m_iterator->line() + 1u; }
size_t display_column() const;