mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Coalesce the current line into a single chunk when moving away from it.
This commit is contained in:
parent
e02eca2a5e
commit
efd5aae217
Notes:
sideshowbarker
2024-07-19 16:08:36 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/efd5aae217d
4 changed files with 20 additions and 0 deletions
|
@ -172,6 +172,7 @@ void Editor::move_down()
|
|||
{
|
||||
if (m_cursor.line() >= max_line())
|
||||
return;
|
||||
coalesce_current_line();
|
||||
m_cursor.move_by(1, 0);
|
||||
if (m_cursor.column() > max_column())
|
||||
m_cursor.set_column(max_column());
|
||||
|
@ -179,10 +180,16 @@ void Editor::move_down()
|
|||
update_scroll_position_if_needed();
|
||||
}
|
||||
|
||||
void Editor::coalesce_current_line()
|
||||
{
|
||||
m_document->lines()[m_cursor.line()].coalesce();
|
||||
}
|
||||
|
||||
void Editor::move_up()
|
||||
{
|
||||
if (m_cursor.line() == 0)
|
||||
return;
|
||||
coalesce_current_line();
|
||||
m_cursor.move_by(-1, 0);
|
||||
if (m_cursor.column() > max_column())
|
||||
m_cursor.set_column(max_column());
|
||||
|
|
|
@ -56,6 +56,7 @@ private:
|
|||
void insert_at_cursor(int ch);
|
||||
|
||||
void exec_command();
|
||||
void coalesce_current_line();
|
||||
|
||||
OwnPtr<Document> m_document;
|
||||
|
||||
|
|
|
@ -94,3 +94,13 @@ std::tuple<size_t, size_t> Line::chunk_index_for_position(size_t position)
|
|||
ASSERT(false);
|
||||
return std::make_tuple(0, 0);
|
||||
}
|
||||
|
||||
void Line::coalesce()
|
||||
{
|
||||
if (m_chunks.size() <= 1)
|
||||
return;
|
||||
|
||||
auto contents = data();
|
||||
m_chunks.clear();
|
||||
m_chunks.push_back(Chunk{ contents });
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
void insert(size_t index, const std::string&);
|
||||
|
||||
void coalesce();
|
||||
|
||||
private:
|
||||
void append(const std::string&);
|
||||
void prepend(const std::string&);
|
||||
|
|
Loading…
Add table
Reference in a new issue