mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:52:44 +00:00 
			
		
		
		
	Coalesce the current line into a single chunk when moving away from it.
This commit is contained in:
		
							parent
							
								
									e02eca2a5e
								
							
						
					
					
						commit
						efd5aae217
					
				
					 4 changed files with 20 additions and 0 deletions
				
			
		|  | @ -172,6 +172,7 @@ void Editor::move_down() | ||||||
| { | { | ||||||
|     if (m_cursor.line() >= max_line()) |     if (m_cursor.line() >= max_line()) | ||||||
|         return; |         return; | ||||||
|  |     coalesce_current_line(); | ||||||
|     m_cursor.move_by(1, 0); |     m_cursor.move_by(1, 0); | ||||||
|     if (m_cursor.column() > max_column()) |     if (m_cursor.column() > max_column()) | ||||||
|         m_cursor.set_column(max_column()); |         m_cursor.set_column(max_column()); | ||||||
|  | @ -179,10 +180,16 @@ void Editor::move_down() | ||||||
|     update_scroll_position_if_needed(); |     update_scroll_position_if_needed(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Editor::coalesce_current_line() | ||||||
|  | { | ||||||
|  |     m_document->lines()[m_cursor.line()].coalesce(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Editor::move_up() | void Editor::move_up() | ||||||
| { | { | ||||||
|     if (m_cursor.line() == 0) |     if (m_cursor.line() == 0) | ||||||
|         return; |         return; | ||||||
|  |     coalesce_current_line(); | ||||||
|     m_cursor.move_by(-1, 0); |     m_cursor.move_by(-1, 0); | ||||||
|     if (m_cursor.column() > max_column()) |     if (m_cursor.column() > max_column()) | ||||||
|         m_cursor.set_column(max_column()); |         m_cursor.set_column(max_column()); | ||||||
|  |  | ||||||
|  | @ -56,6 +56,7 @@ private: | ||||||
|     void insert_at_cursor(int ch); |     void insert_at_cursor(int ch); | ||||||
| 
 | 
 | ||||||
|     void exec_command(); |     void exec_command(); | ||||||
|  |     void coalesce_current_line(); | ||||||
| 
 | 
 | ||||||
|     OwnPtr<Document> m_document; |     OwnPtr<Document> m_document; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -94,3 +94,13 @@ std::tuple<size_t, size_t> Line::chunk_index_for_position(size_t position) | ||||||
|     ASSERT(false); |     ASSERT(false); | ||||||
|     return std::make_tuple(0, 0); |     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 }); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -30,6 +30,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     void insert(size_t index, const std::string&); |     void insert(size_t index, const std::string&); | ||||||
| 
 | 
 | ||||||
|  |     void coalesce(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     void append(const std::string&); |     void append(const std::string&); | ||||||
|     void prepend(const std::string&); |     void prepend(const std::string&); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling