diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-07 16:49:04 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-07 16:49:21 +0100 |
commit | 43d56b6f3a45dd2f92f4fd7b1cf7a8bdf0cb57ba (patch) | |
tree | 65f48098d42fa4e1a304c22bb61d85bf2c460822 /AK | |
parent | a64b71fb3d47676981d7b58c5b356817960dc694 (diff) | |
download | serenity-43d56b6f3a45dd2f92f4fd7b1cf7a8bdf0cb57ba.zip |
GTextEditor: Support splitting lines at the cursor with the Return key.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Vector.h | 20 |
1 files changed, 15 insertions, 5 deletions
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; } |