remove tabstop from GapBuffer

This commit is contained in:
Josh Holtrop 2016-12-07 23:09:06 -05:00
parent 5f3831965e
commit 1b6038a3cd
6 changed files with 7 additions and 10 deletions

View File

@ -104,7 +104,7 @@ bool Buffer::write_to_file(const char * filename)
m_gap_buffer->compact(); m_gap_buffer->compact();
Cursor start_of_line(&*m_gap_buffer, m_encoding); Cursor start_of_line(&*m_gap_buffer, m_encoding, 4u);
size_t bytes_written = 0u; size_t bytes_written = 0u;
while (start_of_line.valid()) while (start_of_line.valid())

View File

@ -18,7 +18,7 @@ public:
std::shared_ptr<Cursor> add_cursor() std::shared_ptr<Cursor> add_cursor()
{ {
return std::make_shared<Cursor>(&*m_gap_buffer, m_encoding); return std::make_shared<Cursor>(&*m_gap_buffer, m_encoding, 4u);
} }
auto get_string() { return m_gap_buffer->get_string(); } auto get_string() { return m_gap_buffer->get_string(); }

View File

@ -154,8 +154,7 @@ bool Cursor::go_right(bool allow_eol)
uint32_t chr = *m_iterator; uint32_t chr = *m_iterator;
if (chr == '\t') if (chr == '\t')
{ {
uint8_t tabstop = m_iterator.gap_buffer()->tabstop; m_column += m_tabstop - (m_column + 1u) % m_tabstop;
m_column += tabstop - (m_column + 1u) % tabstop;
} }
else else
{ {
@ -203,7 +202,7 @@ void Cursor::init_column()
{ {
if (*m_iterator == '\t') if (*m_iterator == '\t')
{ {
m_column = m_iterator.gap_buffer()->tabstop - 1u; m_column = m_tabstop - 1u;
} }
else else
{ {

View File

@ -55,10 +55,11 @@ protected:
class Cursor class Cursor
{ {
public: public:
Cursor(GapBuffer * gap_buffer, Encoding::Type encoding) Cursor(GapBuffer * gap_buffer, Encoding::Type encoding, uint8_t tabstop)
: m_iterator(gap_buffer, encoding) : m_iterator(gap_buffer, encoding)
{ {
m_line = 0u; m_line = 0u;
m_tabstop = tabstop;
init_column(); init_column();
} }
bool is_start_of_line(); bool is_start_of_line();
@ -86,6 +87,7 @@ protected:
Iterator m_iterator; Iterator m_iterator;
size_t m_line; size_t m_line;
size_t m_column; size_t m_column;
uint8_t m_tabstop;
void init_column(); void init_column();
void forward_to_column(size_t target_column); void forward_to_column(size_t target_column);

View File

@ -8,7 +8,6 @@ GapBuffer::GapBuffer()
m_buffer_size = System::page_size; m_buffer_size = System::page_size;
m_size = 0u; m_size = 0u;
m_gap_position = 0u; m_gap_position = 0u;
tabstop = 4u;
} }
GapBuffer::GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size) GapBuffer::GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size)
@ -17,7 +16,6 @@ GapBuffer::GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size)
m_buffer_size = buffer_size; m_buffer_size = buffer_size;
m_size = size; m_size = size;
m_gap_position = size; m_gap_position = size;
tabstop = 4u;
} }
GapBuffer::~GapBuffer() GapBuffer::~GapBuffer()

View File

@ -10,8 +10,6 @@
class GapBuffer class GapBuffer
{ {
public: public:
uint8_t tabstop;
GapBuffer(); GapBuffer();
GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size); GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size);
~GapBuffer(); ~GapBuffer();