diff --git a/include/internal/ui/text_mode.h b/include/internal/ui/text_mode.h index d499b98..23245c7 100644 --- a/include/internal/ui/text_mode.h +++ b/include/internal/ui/text_mode.h @@ -15,7 +15,7 @@ struct TextMode { TextMode(BEd &); std::pair run(); - void grow(size_t required_height); + void grow(); void redraw(); }; } // namespace bed::internal::ui diff --git a/src/internal/ui/text_mode/text_mode.cc b/src/internal/ui/text_mode/text_mode.cc index 69c27f2..eca9ded 100644 --- a/src/internal/ui/text_mode/text_mode.cc +++ b/src/internal/ui/text_mode/text_mode.cc @@ -42,9 +42,8 @@ std::pair TextMode::run() { cmd.erase(--cursor, 1); } } else if (res.text[0] == '\n') { - size_t lines = 1 + std::count(cmd.begin(), cmd.end(), '\n'); - grow(lines + 1); cmd.insert(cursor++, 1, '\n'); + grow(); } else { cmd.insert(cursor, res.text); cursor += res.text.size(); @@ -55,6 +54,7 @@ std::pair TextMode::run() { case io::KeyEvent::KeyType::PASTE: cmd.insert(cursor, res.text); cursor += res.text.size(); + grow(); break; case io::KeyEvent::KeyType::SPECIAL: switch (res.special_key) { @@ -137,7 +137,8 @@ std::pair TextMode::run() { return {vase::Shard::from_string(cmd.data(), cmd.length(), true), false}; } -void TextMode::grow(size_t required_height) { +void TextMode::grow() { + size_t required_height = 1 + std::count(cmd.begin(), cmd.end(), '\n'); auto [rows, cols] = bed.io.terminal_size(); term_height = rows; term_width = cols;