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, }, ); 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 = {} },