Coalesce the current line into a single chunk when moving away from it.

This commit is contained in:
Andreas Kling 2018-12-04 13:38:42 +01:00
parent e02eca2a5e
commit efd5aae217
Notes: sideshowbarker 2024-07-19 16:08:36 +09:00
4 changed files with 20 additions and 0 deletions

View file

@ -172,6 +172,7 @@ void Editor::move_down()
{
if (m_cursor.line() >= max_line())
return;
coalesce_current_line();
m_cursor.move_by(1, 0);
if (m_cursor.column() > max_column())
m_cursor.set_column(max_column());
@ -179,10 +180,16 @@ void Editor::move_down()
update_scroll_position_if_needed();
}
void Editor::coalesce_current_line()
{
m_document->lines()[m_cursor.line()].coalesce();
}
void Editor::move_up()
{
if (m_cursor.line() == 0)
return;
coalesce_current_line();
m_cursor.move_by(-1, 0);
if (m_cursor.column() > max_column())
m_cursor.set_column(max_column());

View file

@ -56,6 +56,7 @@ private:
void insert_at_cursor(int ch);
void exec_command();
void coalesce_current_line();
OwnPtr<Document> m_document;

View file

@ -94,3 +94,13 @@ std::tuple<size_t, size_t> Line::chunk_index_for_position(size_t position)
ASSERT(false);
return std::make_tuple(0, 0);
}
void Line::coalesce()
{
if (m_chunks.size() <= 1)
return;
auto contents = data();
m_chunks.clear();
m_chunks.push_back(Chunk{ contents });
}

View file

@ -30,6 +30,8 @@ public:
void insert(size_t index, const std::string&);
void coalesce();
private:
void append(const std::string&);
void prepend(const std::string&);