Don't clear rectangular selection on size change.

This commit is contained in:
Martín Lucas Golini
2026-03-12 20:33:05 -03:00
parent 382a5d2476
commit 752ef139a2
2 changed files with 41 additions and 9 deletions

View File

@@ -1047,10 +1047,17 @@ void TerminalEmulator::historyReflow( int old_col, int new_col ) {
}
if ( has_sel ) {
if ( i == ob_abs_y )
ob_logical_offset = logical_len + ob_x;
if ( i == oe_abs_y )
oe_logical_offset = logical_len + oe_x;
if ( mSel.type == SEL_RECTANGULAR ) {
if ( i == ob_abs_y )
mSel.ob.y = new_len;
if ( i == oe_abs_y )
mSel.oe.y = new_len;
} else {
if ( i == ob_abs_y )
ob_logical_offset = logical_len + ob_x;
if ( i == oe_abs_y )
oe_logical_offset = logical_len + oe_x;
}
}
memcpy( logical + logical_len, line, old_col * sizeof( TerminalGlyph ) );
@@ -2741,8 +2748,8 @@ void TerminalEmulator::tresize( int col, int row ) {
}
bool has_sel = mSel.ob.x != -1;
// Rectangular selections and alt-screen selections are not reflowed.
if ( has_sel && ( mSel.type == SEL_RECTANGULAR || mSel.alt || is_alt ) ) {
// Alt-screen selections are not reflowed.
if ( has_sel && ( mSel.alt || is_alt ) ) {
selclear();
has_sel = false;
}

View File

@@ -568,7 +568,32 @@ UTEST(eterm, selection_rectangular_reflow) {
// Resize to 5 columns.
term->resize(5, 24);
// Rectangular selections are currently cleared on resize.
EXPECT_FALSE(term->hasSelection());
EXPECT_STDSTREQ("", term->getSelection());
// Rectangular selections should be preserved.
EXPECT_TRUE(term->hasSelection());
EXPECT_STDSTREQ("BC\nGH", term->getSelection());
}
UTEST(eterm, selection_rectangular_resize_no_reflow) {
auto pty = std::make_unique<MockPty>();
auto process = std::make_unique<MockProcess>();
auto display = std::make_shared<MockDisplay>();
auto term = TerminalEmulator::create(std::move(pty), std::move(process), display, 100);
// Initial 80x24.
term->write("ABCDE\r\n", 7);
term->write("FGHIJ\r\n", 7);
term->update();
// Select BC and GH (Rectangular)
term->selstart(1, 0, 0);
term->selextend(2, 1, 2, 0); // type 2 = Rectangular
EXPECT_STDSTREQ("BC\nGH", term->getSelection());
// Resize to 90 columns (wider, no reflow needed)
term->resize(90, 24);
// It should still be selected
EXPECT_TRUE(term->hasSelection());
EXPECT_STDSTREQ("BC\nGH", term->getSelection());
}