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 &); TextMode(BEd &);
std::pair<vase::Shard *, bool> run(); std::pair<vase::Shard *, bool> run();
void grow(size_t required_height); void grow();
void redraw(); void redraw();
}; };
} // namespace bed::internal::ui } // namespace bed::internal::ui
+4 -3
View File
@@ -42,9 +42,8 @@ std::pair<vase::Shard *, bool> TextMode::run() {
cmd.erase(--cursor, 1); cmd.erase(--cursor, 1);
} }
} else if (res.text[0] == '\n') { } 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'); cmd.insert(cursor++, 1, '\n');
grow();
} else { } else {
cmd.insert(cursor, res.text); cmd.insert(cursor, res.text);
cursor += res.text.size(); cursor += res.text.size();
@@ -55,6 +54,7 @@ std::pair<vase::Shard *, bool> TextMode::run() {
case io::KeyEvent::KeyType::PASTE: case io::KeyEvent::KeyType::PASTE:
cmd.insert(cursor, res.text); cmd.insert(cursor, res.text);
cursor += res.text.size(); cursor += res.text.size();
grow();
break; break;
case io::KeyEvent::KeyType::SPECIAL: case io::KeyEvent::KeyType::SPECIAL:
switch (res.special_key) { 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}; 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(); auto [rows, cols] = bed.io.terminal_size();
term_height = rows; term_height = rows;
term_width = cols; term_width = cols;