aboutsummaryrefslogtreecommitdiff
path: root/src/pane.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-04-09 17:51:28 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-04-09 17:52:09 +0300
commit953ff58e9febfc428ebef4db98e3b496ba487d69 (patch)
tree9ad7b9308fa73cac0a8c1876fcd8d58264d4d1ad /src/pane.rs
parentbe271f8dbe6abd9593cdf832e1cc6e1108df6fab (diff)
fix: autoscroll and clear mouse text selections
Diffstat (limited to 'src/pane.rs')
-rw-r--r--src/pane.rs42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/pane.rs b/src/pane.rs
index a578eb33..192cb064 100644
--- a/src/pane.rs
+++ b/src/pane.rs
@@ -1112,11 +1112,8 @@ fn ghostty_extract_selection(
selection: &crate::selection::Selection,
) -> Result<String, crate::ghostty::Error> {
let ((start_row, start_col), (end_row, end_col)) = selection.ordered_cells();
- core.terminal.read_text_viewport(
- (start_col, u32::from(start_row)),
- (end_col, u32::from(end_row)),
- false,
- )
+ core.terminal
+ .read_text_screen((start_col, start_row), (end_col, end_row), false)
}
fn ghostty_screen_row(
@@ -1868,9 +1865,19 @@ impl PaneRuntime {
#[cfg(test)]
impl PaneRuntime {
pub(crate) fn test_with_screen_bytes(cols: u16, rows: u16, bytes: &[u8]) -> Self {
+ Self::test_with_scrollback_bytes(cols, rows, 0, bytes)
+ }
+
+ pub(crate) fn test_with_scrollback_bytes(
+ cols: u16,
+ rows: u16,
+ scrollback_limit_bytes: usize,
+ bytes: &[u8],
+ ) -> Self {
let (tx, _rx) = mpsc::channel(4);
let (resize_tx, _resize_rx) = mpsc::channel(1);
- let mut terminal = crate::ghostty::Terminal::new(cols, rows, 0).unwrap();
+ let mut terminal =
+ crate::ghostty::Terminal::new(cols, rows, scrollback_limit_bytes).unwrap();
terminal.write(bytes);
Self {
@@ -2167,6 +2174,29 @@ mod tests {
}
#[test]
+ fn extract_selection_reads_screen_rows_not_current_viewport() {
+ let (tx, _rx) = mpsc::channel(4);
+ let mut terminal = crate::ghostty::Terminal::new(8, 3, 1024).unwrap();
+ write_numbered_lines(&mut terminal, 8);
+ let pane = GhosttyPaneTerminal::new(terminal, tx).unwrap();
+
+ pane.set_scroll_offset_from_bottom(3);
+ let metrics = pane
+ .scroll_metrics()
+ .expect("scroll metrics after initial scroll");
+ let mut selection =
+ crate::selection::Selection::anchor(PaneId::from_raw(1), 0, 0, Some(metrics));
+ selection.drag(5, 2, Rect::new(0, 0, 8, 3), Some(metrics));
+
+ pane.scroll_reset();
+
+ let text = pane
+ .extract_selection(&selection)
+ .expect("selection should extract text");
+ assert_eq!(text, "000003\n000004\n000005");
+ }
+
+ #[test]
fn recent_unwrapped_text_ignores_soft_wraps() {
let (tx, _rx) = mpsc::channel(4);
let mut terminal = crate::ghostty::Terminal::new(5, 3, 100).unwrap();