mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-01 08:48:49 +00:00
GTextEditor: Merge with previous line if backspacing at column 0.
This commit is contained in:
parent
6094f592a9
commit
38662f884d
Notes:
sideshowbarker
2024-07-19 15:08:26 +09:00
Author: https://github.com/awesomekling
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 (m_cursor.column() > 0) {
|
||||
// Backspace within line
|
||||
current_line().remove(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;
|
||||
}
|
||||
|
||||
|
@ -343,6 +353,14 @@ int GTextEditor::Line::width(const Font& font) const
|
|||
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)
|
||||
{
|
||||
insert(length(), ch);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue