summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/look.zig7
-rw-r--r--src/ninep/ctl.zig2
2 files changed, 7 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) };
}
};
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 7321f569..d815632d 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2442,6 +2442,8 @@ test "a remembered place is clamped to the file as it is now, its selection's tw
try testing.expect(std.mem.endsWith(u8, back.file.?.path, "/c.txt"));
try testing.expect(back.body.cur_row <= 1);
try testing.expect(back.body.vsel.active);
+ // Its ends clamped to the last character, `two`'s `o`, not its newline.
+ try testing.expect(back.body.cur_col <= 2 and back.body.vsel.col <= 2);
}
test "size is monotonic: growing is never refused, and a size once taken is taken again" {