add Buffer::Cursor type alias for GapBuffer::Cursor

This commit is contained in:
Josh Holtrop 2016-11-30 21:06:59 -05:00
parent e57c71855a
commit f14db217d2
3 changed files with 12 additions and 11 deletions

View File

@ -12,6 +12,8 @@ class Buffer
public:
Buffer(const char * filename = nullptr);
bool write_to_file(const char * filename);
typedef GapBuffer::Cursor Cursor;
auto add_cursor() { return m_gap_buffer->add_cursor(); }
auto get_string() { return m_gap_buffer->get_string(); }

View File

@ -29,7 +29,7 @@ void BufferPane::update_cursor_row()
int BufferPane::screen_rows_below_cursor(int stop_at)
{
GapBuffer::Cursor cursor = *m_cursor;
Buffer::Cursor cursor = *m_cursor;
size_t column = cursor.column();
cursor.go_end_of_line(false);
int rows = (cursor.column() / m_columns) - (column / m_columns);
@ -43,11 +43,11 @@ int BufferPane::screen_rows_below_cursor(int stop_at)
int BufferPane::screen_rows_above_cursor(int stop_at)
{
GapBuffer::Cursor cursor = *m_cursor;
Buffer::Cursor cursor = *m_cursor;
int rows = cursor.column() / m_columns;
while ((rows < stop_at) && cursor.go_up(0u))
{
GapBuffer::Cursor cursor2 = cursor;
Buffer::Cursor cursor2 = cursor;
cursor2.go_end_of_line(false);
rows += (cursor2.column() / m_columns) + 1;
}
@ -58,11 +58,11 @@ void BufferPane::draw()
{
update_cursor_row();
int screen_row = m_cursor_row - m_cursor->column() / m_columns;
GapBuffer::Cursor iter_cursor = *m_cursor;
Buffer::Cursor iter_cursor = *m_cursor;
iter_cursor.go_start_of_line();
while ((screen_row > 0) && iter_cursor.go_up(0u))
{
GapBuffer::Cursor cursor2 = iter_cursor;
Buffer::Cursor cursor2 = iter_cursor;
cursor2.go_end_of_line(false);
screen_row -= (1 + cursor2.column() / m_columns);
}
@ -78,9 +78,9 @@ void BufferPane::draw()
}
}
void BufferPane::draw_buffer_line(int screen_row, const GapBuffer::Cursor & cursor)
void BufferPane::draw_buffer_line(int screen_row, const Buffer::Cursor & cursor)
{
GapBuffer::Cursor iter_cursor = cursor;
Buffer::Cursor iter_cursor = cursor;
while (!iter_cursor.is_end_of_line(true))
{
int draw_row = screen_row + (iter_cursor.column() / m_columns);

View File

@ -1,7 +1,6 @@
#ifndef BUFFERPANE_H
#define BUFFERPANE_H
#include "GapBuffer.h"
#include "Buffer.h"
#include "Pane.h"
#include "Font.h"
@ -16,7 +15,7 @@ public:
std::shared_ptr<GL> gl);
void resize(int width, int height) override;
void draw();
std::shared_ptr<GapBuffer::Cursor> cursor() { return m_cursor; }
std::shared_ptr<Buffer::Cursor> cursor() { return m_cursor; }
protected:
int effective_scroll_offset()
@ -26,7 +25,7 @@ protected:
int screen_rows_below_cursor(int stop_at);
int screen_rows_above_cursor(int stop_at);
void update_cursor_row();
void draw_buffer_line(int screen_row, const GapBuffer::Cursor & cursor);
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
void draw_buffer_character(int screen_column, int screen_row, uint32_t character);
void draw_cursor(int screen_column, int screen_row, bool insert_mode);
void colrow_to_xy(int col, int row, int * x, int * y);
@ -38,7 +37,7 @@ protected:
int m_columns;
int m_scroll_offset;
int m_cursor_row;
std::shared_ptr<GapBuffer::Cursor> m_cursor;
std::shared_ptr<Buffer::Cursor> m_cursor;
};
#endif