mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-08 16:55:01 +00:00
TextEditor: Add utility to keep a range of text within a line
This commit is contained in:
committed by
Andrew Kaster
parent
31290c8527
commit
9aa00a6d70
@@ -246,6 +246,19 @@ void TextDocumentLine::remove_range(TextDocument& document, size_t start, size_t
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::keep_range(TextDocument& document, size_t start_index, size_t length)
|
||||
{
|
||||
VERIFY(start_index + length < m_text.size());
|
||||
|
||||
Vector<u32> new_data;
|
||||
new_data.ensure_capacity(m_text.size());
|
||||
for (size_t i = start_index; i <= (start_index + length); i++)
|
||||
new_data.append(m_text[i]);
|
||||
|
||||
m_text = move(new_data);
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::truncate(TextDocument& document, size_t length)
|
||||
{
|
||||
m_text.resize(length);
|
||||
|
||||
@@ -179,6 +179,7 @@ public:
|
||||
void truncate(TextDocument&, size_t length);
|
||||
void clear(TextDocument&);
|
||||
void remove_range(TextDocument&, size_t start, size_t length);
|
||||
void keep_range(TextDocument&, size_t start_index, size_t end_index);
|
||||
|
||||
size_t first_non_whitespace_column() const;
|
||||
Optional<size_t> last_non_whitespace_column() const;
|
||||
|
||||
Reference in New Issue
Block a user