diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-12-04 13:38:42 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-12-04 13:39:31 +0100 |
commit | efd5aae217d2ba46569f8a89b8c98dd350163bbc (patch) | |
tree | de464b10585c8be559017e9f5eb38a7100b179e8 /Editor | |
parent | e02eca2a5e6c605660f9ad4080f52b80bc67e931 (diff) | |
download | serenity-efd5aae217d2ba46569f8a89b8c98dd350163bbc.zip |
Coalesce the current line into a single chunk when moving away from it.
Diffstat (limited to 'Editor')
-rw-r--r-- | Editor/Editor.cpp | 7 | ||||
-rw-r--r-- | Editor/Editor.h | 1 | ||||
-rw-r--r-- | Editor/Line.cpp | 10 | ||||
-rw-r--r-- | Editor/Line.h | 2 |
4 files changed, 20 insertions, 0 deletions
diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index be16065e8e..252fc48bd0 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -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()); diff --git a/Editor/Editor.h b/Editor/Editor.h index ec1f53ff11..fc3f528b54 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -56,6 +56,7 @@ private: void insert_at_cursor(int ch); void exec_command(); + void coalesce_current_line(); OwnPtr<Document> m_document; diff --git a/Editor/Line.cpp b/Editor/Line.cpp index 7b2343210c..3b9624a11c 100644 --- a/Editor/Line.cpp +++ b/Editor/Line.cpp @@ -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 }); +} diff --git a/Editor/Line.h b/Editor/Line.h index dd8e39c181..8ad7337551 100644 --- a/Editor/Line.h +++ b/Editor/Line.h @@ -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&); |