From 43d56b6f3a45dd2f92f4fd7b1cf7a8bdf0cb57ba Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 7 Mar 2019 16:49:04 +0100 Subject: GTextEditor: Support splitting lines at the cursor with the Return key. --- AK/Vector.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'AK') diff --git a/AK/Vector.h b/AK/Vector.h index 13ffb4df64..02f3997fd5 100644 --- a/AK/Vector.h +++ b/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; } -- cgit v1.2.3