From 18c63c0526399149594229cdcaf657f583c1bd48 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 12 Feb 2022 09:47:03 -0700 Subject: [PATCH] fix copying trailing whitespace from wrapped lines refs: #1635 --- docs/changelog.md | 1 + wezterm-gui/src/termwindow/selection.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 7fcdebfeb..140967212 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -66,6 +66,7 @@ As features stabilize some brief notes about them will accumulate here. * Shaping combining sequences like `e U+20d7` could "lose" the vector symbol if the font produced an entry with no `x_advance`. [#1617](https://github.com/wez/wezterm/issues/1617) * Setting the cursor color via escape sequences now take precedence over `force_reverse_video_cursor`. [#1625](https://github.com/wez/wezterm/issues/1625) * Fixed Detection of DECSDM support via DECRQM/DECRPM, Correct sixel image placement when DECSDM is set and VT340 default sixel colors. Thanks to [Autumn](https://github.com/autumnmeowmeow)! [#1577](https://github.com/wez/wezterm/pull/1577) +* Fixed missing whitespace from intermediate lines when copying a wrapped logical line [#1635](https://github.com/wez/wezterm/issues/1635) ### 20220101-133340-7edc5b5a diff --git a/wezterm-gui/src/termwindow/selection.rs b/wezterm-gui/src/termwindow/selection.rs index 3c083e0e0..208c91c3a 100644 --- a/wezterm-gui/src/termwindow/selection.rs +++ b/wezterm-gui/src/termwindow/selection.rs @@ -21,13 +21,21 @@ impl super::TermWindow { if !s.is_empty() && !last_was_wrapped { s.push('\n'); } + let last_idx = line.physical_lines.len().saturating_sub(1); for (idx, phys) in line.physical_lines.iter().enumerate() { let this_row = line.first_row + idx as StableRowIndex; if this_row >= first_row && this_row < last_row { let last_phys_idx = phys.cells().len().saturating_sub(1); let cols = sel.cols_for_row(this_row); let last_col_idx = cols.end.saturating_sub(1).min(last_phys_idx); - s.push_str(phys.columns_as_str(cols).trim_end()); + let col_span = phys.columns_as_str(cols); + // Only trim trailing whitespace if we are the last line + // in a wrapped sequence + if idx == last_idx { + s.push_str(col_span.trim_end()); + } else { + s.push_str(&col_span); + } last_was_wrapped = last_col_idx == last_phys_idx && phys