mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:18:12 +00:00
GTextEditor: Support forward delete/merge with the Delete key.
This commit is contained in:
parent
ac78cdae46
commit
a64b71fb3d
1 changed files with 25 additions and 1 deletions
|
@ -190,20 +190,42 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||||
if (m_cursor.column() > 0) {
|
if (m_cursor.column() > 0) {
|
||||||
// Backspace within line
|
// Backspace within line
|
||||||
current_line().remove(m_cursor.column() - 1);
|
current_line().remove(m_cursor.column() - 1);
|
||||||
|
update_scrollbar_ranges();
|
||||||
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) {
|
if (m_cursor.column() == 0 && m_cursor.line() != 0) {
|
||||||
// Erase at column 0; merge with previous line
|
// Backspace at column 0; merge with previous line
|
||||||
auto& previous_line = *m_lines[m_cursor.line() - 1];
|
auto& previous_line = *m_lines[m_cursor.line() - 1];
|
||||||
int previous_length = previous_line.length();
|
int previous_length = previous_line.length();
|
||||||
previous_line.append(current_line().characters(), current_line().length());
|
previous_line.append(current_line().characters(), current_line().length());
|
||||||
m_lines.remove(m_cursor.line());
|
m_lines.remove(m_cursor.line());
|
||||||
|
update_scrollbar_ranges();
|
||||||
update();
|
update();
|
||||||
set_cursor(m_cursor.line() - 1, previous_length);
|
set_cursor(m_cursor.line() - 1, previous_length);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!event.modifiers() && event.key() == KeyCode::Key_Delete) {
|
||||||
|
if (m_cursor.column() < current_line().length()) {
|
||||||
|
// Delete within line
|
||||||
|
current_line().remove(m_cursor.column());
|
||||||
|
update_scrollbar_ranges();
|
||||||
|
update_cursor();
|
||||||
|
}
|
||||||
|
if (m_cursor.column() == (current_line().length() + 1) && 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_scrollbar_ranges();
|
||||||
|
update();
|
||||||
|
set_cursor(m_cursor.line(), previous_length);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!event.text().is_empty())
|
if (!event.text().is_empty())
|
||||||
insert_at_cursor(event.text()[0]);
|
insert_at_cursor(event.text()[0]);
|
||||||
|
|
||||||
|
@ -256,6 +278,8 @@ Rect GTextEditor::line_widget_rect(int line_index) const
|
||||||
rect.move_by(-(m_horizontal_scrollbar->value() - padding()), -(m_vertical_scrollbar->value() - padding()));
|
rect.move_by(-(m_horizontal_scrollbar->value() - padding()), -(m_vertical_scrollbar->value() - padding()));
|
||||||
rect.set_width(rect.width() + 1); // Add 1 pixel for when the cursor is on the end.
|
rect.set_width(rect.width() + 1); // Add 1 pixel for when the cursor is on the end.
|
||||||
rect.intersect(this->rect());
|
rect.intersect(this->rect());
|
||||||
|
// This feels rather hackish, but extend the rect to the edge of the content view:
|
||||||
|
rect.set_right(m_vertical_scrollbar->relative_rect().left() - 1);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue