From 995bc546398098def01ebd472dee5d9dda2f51c8 Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:55:01 +0800 Subject: [PATCH] Ensure correct coordinate ordering in selection file write When writing selected text to file, use `topLeft` and `bottomRight` instead of `start` and `end` to ensure correct coordinate ordering. This fixes an issue where selection files could be empty when selecting text in reverse order. - Use `terminal.Selection.topLeft()` for start coordinate - Use `terminal.Selection.bottomRight()` for end coordinate --- src/Surface.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 9a6d2f6db..5b39c6046 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -4293,11 +4293,16 @@ fn writeScreenFile( tmp_dir.deinit(); return; }; + + // Use topLeft and bottomRight to ensure correct coordinate ordering + const tl = sel.topLeft(&self.io.terminal.screen); + const br = sel.bottomRight(&self.io.terminal.screen); + try self.io.terminal.screen.dumpString( buf_writer.writer(), .{ - .tl = sel.start(), - .br = sel.end(), + .tl = tl, + .br = br, .unwrap = true, }, );