Grow text mode properly during pastes.

This commit is contained in:
2026-08-31 13:00:14 +01:00
parent 569b69263a
commit 25f4d8efa8
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ struct TextMode {
TextMode(BEd &);
std::pair<vase::Shard *, bool> run();
void grow(size_t required_height);
void grow();
void redraw();
};
} // namespace bed::internal::ui
+4 -3
View File
@@ -42,9 +42,8 @@ std::pair<vase::Shard *, bool> 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<vase::Shard *, bool> 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<vase::Shard *, bool> 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;