File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -188,9 +188,19 @@ void GTextEditor::keydown_event(GKeyEvent& event)
188
188
189
189
if (!event.modifiers () && event.key () == KeyCode::Key_Backspace) {
190
190
if (m_cursor.column () > 0 ) {
191
+ // Backspace within line
191
192
current_line ().remove (m_cursor.column () - 1 );
192
193
set_cursor (m_cursor.line (), m_cursor.column () - 1 );
193
194
}
195
+ if (m_cursor.column () == 0 && m_cursor.line () != 0 ) {
196
+ // Erase at column 0; merge with previous line
197
+ auto & previous_line = *m_lines[m_cursor.line () - 1 ];
198
+ int previous_length = previous_line.length ();
199
+ previous_line.append (current_line ().characters (), current_line ().length ());
200
+ m_lines.remove (m_cursor.line ());
201
+ update ();
202
+ set_cursor (m_cursor.line () - 1 , previous_length);
203
+ }
194
204
return ;
195
205
}
196
206
@@ -343,6 +353,14 @@ int GTextEditor::Line::width(const Font& font) const
343
353
return font.glyph_width (' x' ) * length ();
344
354
}
345
355
356
+ void GTextEditor::Line::append (const char * characters, int length)
357
+ {
358
+ int old_length = m_text.size () - 1 ;
359
+ m_text.resize (m_text.size () + length);
360
+ memcpy (m_text.data () + old_length, characters, length);
361
+ m_text.last () = 0 ;
362
+ }
363
+
346
364
void GTextEditor::Line::append (char ch)
347
365
{
348
366
insert (length (), ch);
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ class GTextEditor : public GWidget {
72
72
void prepend (char );
73
73
void insert (int index, char );
74
74
void remove (int index);
75
+ void append (const char *, int );
75
76
76
77
private:
77
78
// NOTE: This vector is null terminated.
You can’t perform that action at this time.
0 commit comments