diff --git a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp index cfa0b00dc..3bfc20725 100644 --- a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp @@ -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; } diff --git a/src/tests/unit_tests/eterm_test.cpp b/src/tests/unit_tests/eterm_test.cpp index 9be10171d..0ad0ef3a6 100644 --- a/src/tests/unit_tests/eterm_test.cpp +++ b/src/tests/unit_tests/eterm_test.cpp @@ -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(); + auto process = std::make_unique(); + auto display = std::make_shared(); + 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()); }