mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
GTextEditor: Support splitting lines at the cursor with the Return key.
This commit is contained in:
parent
a64b71fb3d
commit
43d56b6f3a
Notes:
sideshowbarker
2024-07-19 15:08:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/43d56b6f3a4
20
AK/Vector.h
20
AK/Vector.h
@ -252,12 +252,22 @@ public:
|
||||
|
||||
void resize(ssize_t new_size)
|
||||
{
|
||||
ASSERT(new_size >= size());
|
||||
if (!new_size)
|
||||
if (new_size == size())
|
||||
return;
|
||||
ensure_capacity(new_size);
|
||||
for (ssize_t i = size(); i < new_size; ++i)
|
||||
new (m_impl->slot(i)) T;
|
||||
|
||||
if (!new_size) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (new_size > size()) {
|
||||
ensure_capacity(new_size);
|
||||
for (ssize_t i = size(); i < new_size; ++i)
|
||||
new (m_impl->slot(i)) T;
|
||||
} else {
|
||||
for (int i = new_size; i < size(); ++i)
|
||||
m_impl->at(i).~T();
|
||||
}
|
||||
m_impl->m_size = new_size;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ private:
|
||||
void insert(int index, char);
|
||||
void remove(int index);
|
||||
void append(const char*, int);
|
||||
void truncate(int length);
|
||||
|
||||
private:
|
||||
// NOTE: This vector is null terminated.
|
||||
|
Loading…
Reference in New Issue
Block a user