mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 12:07:44 +00:00
TextEditor: Add utility to keep a range of text within a line
This commit is contained in:
parent
31290c8527
commit
9aa00a6d70
2 changed files with 14 additions and 0 deletions
|
@ -246,6 +246,19 @@ void TextDocumentLine::remove_range(TextDocument& document, size_t start, size_t
|
||||||
document.update_views({});
|
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)
|
void TextDocumentLine::truncate(TextDocument& document, size_t length)
|
||||||
{
|
{
|
||||||
m_text.resize(length);
|
m_text.resize(length);
|
||||||
|
|
|
@ -179,6 +179,7 @@ public:
|
||||||
void truncate(TextDocument&, size_t length);
|
void truncate(TextDocument&, size_t length);
|
||||||
void clear(TextDocument&);
|
void clear(TextDocument&);
|
||||||
void remove_range(TextDocument&, size_t start, size_t length);
|
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;
|
size_t first_non_whitespace_column() const;
|
||||||
Optional<size_t> last_non_whitespace_column() const;
|
Optional<size_t> last_non_whitespace_column() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue