summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig23
1 files changed, 16 insertions, 7 deletions
diff --git a/core/look.zig b/core/look.zig
index 53c26943..2e3d9e57 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -727,7 +727,7 @@ pub fn advanceLookHover(p: *Pardes) void {
p.look_hover_wait = null;
}
-pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, keep }) void {
+pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, keep }) void {
if (id >= MAX_PANES) return;
const pane = p.panes[id] orelse return;
p.view().active = id;
@@ -735,7 +735,13 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke
pane.body.normal.clear();
// A kind's place is its `address`'s (lookKind).
if (pane.addon != null) return;
- if (at.line == 0) return;
+ if (at_in.line == 0) return;
+ // A place's line is the file's: past the `Changes` layer's lines.
+ var at = at_in;
+ if (pane.file) |*f| if (f.read_only.len > 0) {
+ at.line = @intCast(panes.File.bufferRow(f, at.line - 1) + 1);
+ if (at.end_line != 0) at.end_line = @intCast(panes.File.bufferRow(f, at.end_line - 1) + 1);
+ };
if (pane.file) |*f| {
if (at.line > panes.File.nlines(p.gpa, f)) return;
if (landing == .center) {
@@ -1108,14 +1114,16 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)});
};
if (!by_serial and path.len > 0 and (f.output != null or !std.mem.endsWith(u8, f.path, std.Io.Dir.path.basename(path)))) return;
- var a: Addr = .{ .text = f.content, .lim = null, .expr = expr };
+ // An address is the file's (`:N` its line N): its text, the `Changes`
+ // layer's lines none of it (File.fileText), its dot there (fileDot).
+ var a: Addr = .{ .text = panes.File.fileText(&f, p.scratch.allocator()) catch |err| return p.reportError(.at(id), "look", err), .lim = null, .expr = expr };
// A miss names the file it was looked for in, and is that file's pane's.
var cut: [miss_path_cap + "…".len]u8 = undefined;
const name = missText(f.path, &cut);
// A look whose address fails opens nothing: a pane it opened to read
// the address in goes again, the miss said from the pane it came from.
const opened_here = open == null and target != id;
- const r = a.address(ninep_pane.dotOf(pane)) orelse {
+ const r = a.address(ninep_pane.fileDot(pane)) orelse {
// A line past the end says so as `file:N` does, whichever way it
// was written: `<file>:N has no line N`.
if (std.fmt.parseInt(usize, expr, 10)) |line| {
@@ -1135,7 +1143,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
return missed(p, target, "{s}: {s}", .{ name, why });
}
clearNavigationSelection(p, pane);
- ninep_pane.setDot(p.settings.tab, pane, r);
+ ninep_pane.setFileDot(p.settings.tab, pane, r);
v.active = target;
}
@@ -1391,13 +1399,14 @@ fn noteLookSource(p: *Pardes, id: usize) void {
fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, opened: ?usize) void {
const shown = p.panes[p.view().active] orelse return;
const f = if (shown.file) |*file| file else return;
- if (at.line > panes.File.nlines(p.gpa, f)) {
+ // N is the file's line N (the `Changes` layer's lines have no number).
+ if (at.line > panes.File.nlines(p.gpa, f) - f.read_only.len) {
if (opened) |free| p.removePane(free, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[before] != null) p.view().active = before;
return missedLine(p, id, path, at.line);
}
if (at.line > 0 and at.col == 0 and at.end_line == 0) {
- const start = modal.lineStartOffset(f.content, at.line - 1);
+ const start = modal.lineStartOffset(f.content, panes.File.bufferRow(f, at.line - 1));
const next = std.mem.indexOfScalarPos(u8, f.content, start, '\n');
const end = if (next) |i| i + 1 else f.content.len;
@import("ninep/pane.zig").setDot(p.settings.tab, shown, .{ .q0 = @intCast(start), .q1 = @intCast(end) });