From c62f64866c8183ca15a16e879c71a828c73a46f1 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 1/2] 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, }, ); From a1f7a957636383fb1abf71088802028983a061bf Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Tue, 31 Dec 2024 01:14:46 +0800 Subject: [PATCH 2/2] Add pin order assertion in Pin.pageIterator --- src/terminal/PageList.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index ca928fda6..5fb49ea66 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -3413,6 +3413,16 @@ pub const Pin = struct { direction: Direction, limit: ?Pin, ) PageIterator { + if (build_config.slow_runtime_safety) { + if (limit) |l| { + // Check the order according to the iteration direction. + switch (direction) { + .right_down => assert(self.eql(l) or self.before(l)), + .left_up => assert(self.eql(l) or l.before(self)), + } + } + } + return .{ .row = self, .limit = if (limit) |p| .{ .row = p } else .{ .none = {} },