From f14db217d257cdefa22cf58d645220c5f44a1764 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 30 Nov 2016 21:06:59 -0500 Subject: [PATCH] add Buffer::Cursor type alias for GapBuffer::Cursor --- src/core/Buffer.h | 2 ++ src/gui/BufferPane.cc | 14 +++++++------- src/gui/BufferPane.h | 7 +++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/core/Buffer.h b/src/core/Buffer.h index 2625afe..39bbc59 100644 --- a/src/core/Buffer.h +++ b/src/core/Buffer.h @@ -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(); } diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 60a7b60..7e545cb 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -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); diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 62413e9..2d2d926 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -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); void resize(int width, int height) override; void draw(); - std::shared_ptr cursor() { return m_cursor; } + std::shared_ptr 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 m_cursor; + std::shared_ptr m_cursor; }; #endif