mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 06:15:07 +00:00
GTextEditor: Merge with previous line if backspacing at column 0.
This commit is contained in:
parent
6094f592a9
commit
38662f884d
2 changed files with 19 additions and 0 deletions
|
@ -188,9 +188,19 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||||
|
|
||||||
if (!event.modifiers() && event.key() == KeyCode::Key_Backspace) {
|
if (!event.modifiers() && event.key() == KeyCode::Key_Backspace) {
|
||||||
if (m_cursor.column() > 0) {
|
if (m_cursor.column() > 0) {
|
||||||
|
// Backspace within line
|
||||||
current_line().remove(m_cursor.column() - 1);
|
current_line().remove(m_cursor.column() - 1);
|
||||||
set_cursor(m_cursor.line(), m_cursor.column() - 1);
|
set_cursor(m_cursor.line(), m_cursor.column() - 1);
|
||||||
}
|
}
|
||||||
|
if (m_cursor.column() == 0 && m_cursor.line() != 0) {
|
||||||
|
// Erase at column 0; merge with previous line
|
||||||
|
auto& previous_line = *m_lines[m_cursor.line() - 1];
|
||||||
|
int previous_length = previous_line.length();
|
||||||
|
previous_line.append(current_line().characters(), current_line().length());
|
||||||
|
m_lines.remove(m_cursor.line());
|
||||||
|
update();
|
||||||
|
set_cursor(m_cursor.line() - 1, previous_length);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,6 +353,14 @@ int GTextEditor::Line::width(const Font& font) const
|
||||||
return font.glyph_width('x') * length();
|
return font.glyph_width('x') * length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GTextEditor::Line::append(const char* characters, int length)
|
||||||
|
{
|
||||||
|
int old_length = m_text.size() - 1;
|
||||||
|
m_text.resize(m_text.size() + length);
|
||||||
|
memcpy(m_text.data() + old_length, characters, length);
|
||||||
|
m_text.last() = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void GTextEditor::Line::append(char ch)
|
void GTextEditor::Line::append(char ch)
|
||||||
{
|
{
|
||||||
insert(length(), ch);
|
insert(length(), ch);
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
void prepend(char);
|
void prepend(char);
|
||||||
void insert(int index, char);
|
void insert(int index, char);
|
||||||
void remove(int index);
|
void remove(int index);
|
||||||
|
void append(const char*, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// NOTE: This vector is null terminated.
|
// NOTE: This vector is null terminated.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue