mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-30 05:42:37 +00:00 
			
		
		
		
	TextEditor: The delete key should work even when there's no selection.
This commit is contained in:
		
							parent
							
								
									be4533717a
								
							
						
					
					
						commit
						ed2303e2d8
					
				
					 3 changed files with 30 additions and 24 deletions
				
			
		|  | @ -382,28 +382,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) | |||
|     } | ||||
| 
 | ||||
|     if (event.key() == KeyCode::Key_Delete) { | ||||
|         if (has_selection()) { | ||||
|             delete_selection(); | ||||
|             return; | ||||
|         } | ||||
|         if (m_cursor.column() < current_line().length()) { | ||||
|             // Delete within line
 | ||||
|             current_line().remove(m_cursor.column()); | ||||
|             update_content_size(); | ||||
|             update_cursor(); | ||||
|             return; | ||||
|         } | ||||
|         if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { | ||||
|             // Delete at end of line; merge with next line
 | ||||
|             auto& next_line = *m_lines[m_cursor.line() + 1]; | ||||
|             int previous_length = current_line().length(); | ||||
|             current_line().append(next_line.characters(), next_line.length()); | ||||
|             m_lines.remove(m_cursor.line() + 1); | ||||
|             update_content_size(); | ||||
|             update(); | ||||
|             set_cursor(m_cursor.line(), previous_length); | ||||
|             return; | ||||
|         } | ||||
|         do_delete(); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|  | @ -413,6 +392,32 @@ void GTextEditor::keydown_event(GKeyEvent& event) | |||
|     return GWidget::keydown_event(event); | ||||
| } | ||||
| 
 | ||||
| void GTextEditor::do_delete() | ||||
| { | ||||
|     if (has_selection()) { | ||||
|         delete_selection(); | ||||
|         return; | ||||
|     } | ||||
|     if (m_cursor.column() < current_line().length()) { | ||||
|         // Delete within line
 | ||||
|         current_line().remove(m_cursor.column()); | ||||
|         update_content_size(); | ||||
|         update_cursor(); | ||||
|         return; | ||||
|     } | ||||
|     if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { | ||||
|         // Delete at end of line; merge with next line
 | ||||
|         auto& next_line = *m_lines[m_cursor.line() + 1]; | ||||
|         int previous_length = current_line().length(); | ||||
|         current_line().append(next_line.characters(), next_line.length()); | ||||
|         m_lines.remove(m_cursor.line() + 1); | ||||
|         update_content_size(); | ||||
|         update(); | ||||
|         set_cursor(m_cursor.line(), previous_length); | ||||
|         return; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GTextEditor::insert_at_cursor(const String& text) | ||||
| { | ||||
|     // FIXME: This should obviously not be implemented this way.
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling