summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 12:22:36 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commitc06a666ca4daf0068372e825807007f7bbcf5523 (patch)
tree1c5d7ac673c663586c0d84595e7a54d88d7021f7 /src/look.zig
parent3f4ba3490904da77c4b244c21017fcf94f3bb198 (diff)
downloadpardes-c06a666ca4daf0068372e825807007f7bbcf5523.tar.gz
pardes-c06a666ca4daf0068372e825807007f7bbcf5523.zip
A clamped Recent range ends at a line's last character, never swallowing its newline
A range past the end of a file that had shrunk was clamped to the empty line after its final newline and to one past a line's last character, so the selection took the newline in. Its ends now clamp to the last line and to its last character, as addr's L:C does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig
index 5d16e6eb..6f279769 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1394,11 +1394,14 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
const pane = p.panes[id] orelse return;
const f = if (pane.file) |*file| file else return;
if (!std.mem.eql(u8, f.path, path)) return;
- const n = @max(1, panes.File.nlines(p.gpa, f));
+ // The empty "line" after a final newline is no line to land on.
+ const n = @max(1, panes.File.nlines(p.gpa, f) - @intFromBool(std.mem.endsWith(u8, f.content, "\n")));
const clamp = struct {
fn spot(text: []const u8, lines: usize, line: usize, col: usize) [2]usize {
const l = std.math.clamp(line, 1, lines);
- const width = modal.lineSlice(text, l - 1).len + 1;
+ // Its last character at most, never the newline after it, as
+ // addr's `L:C` clamps.
+ const width = @max(1, modal.lineSlice(text, l - 1).len);
return .{ l, std.math.clamp(col, 1, width) };
}
};