GTextEditor: Support splitting lines at the cursor with the Return key.

This commit is contained in:
Andreas Kling 2019-03-07 16:49:04 +01:00
commit 43d56b6f3a
Notes: sideshowbarker 2024-07-19 15:08:18 +09:00
3 changed files with 30 additions and 6 deletions

View file

@ -240,10 +240,17 @@ void GTextEditor::insert_at_cursor(char ch)
if (at_tail || at_head) {
m_lines.insert(m_cursor.line() + (at_tail ? 1 : 0), make<Line>());
update_scrollbar_ranges();
set_cursor(m_cursor.line() + 1, 0);
update();
set_cursor(m_cursor.line() + 1, 0);
return;
}
auto new_line = make<Line>();
new_line->append(current_line().characters() + m_cursor.column(), current_line().length() - m_cursor.column());
current_line().truncate(m_cursor.column());
m_lines.insert(m_cursor.line() + 1, move(new_line));
update_scrollbar_ranges();
update();
set_cursor(m_cursor.line() + 1, 0);
return;
}
current_line().insert(m_cursor.column(), ch);
@ -414,3 +421,9 @@ void GTextEditor::Line::remove(int index)
m_text.remove(index);
}
}
void GTextEditor::Line::truncate(int length)
{
m_text.resize(length + 1);
m_text.last() = 0;
}