summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TextDocument.cpp
diff options
context:
space:
mode:
authorKyle Lanmon <kyle.lanmon@gmail.com>2022-11-02 23:23:00 -0500
committerAndrew Kaster <andrewdkaster@gmail.com>2022-11-27 18:28:43 -0700
commit9aa00a6d706fddd22d802df554a3e63c138d22f9 (patch)
tree2da8df240fa32366bbd171ba9f58d6061c66305e /Userland/Libraries/LibGUI/TextDocument.cpp
parent31290c8527a66b4ca0f2138123cf63cf9f6842c5 (diff)
downloadserenity-9aa00a6d706fddd22d802df554a3e63c138d22f9.zip
TextEditor: Add utility to keep a range of text within a line
Diffstat (limited to 'Userland/Libraries/LibGUI/TextDocument.cpp')
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 79f5a0723d..2148d02e69 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -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);