diff options
| -rw-r--r-- | core/Trail.zig | 252 | ||||
| -rw-r--r-- | core/layout.zig | 43 | ||||
| -rw-r--r-- | core/look.zig | 134 |
3 files changed, 398 insertions, 31 deletions
diff --git a/core/Trail.zig b/core/Trail.zig index fc163751..63a57c2c 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -74,6 +74,126 @@ pub fn reading(p: *const Pardes, pane: *const Pane) bool { return p.settings.jumps == .walk and isFile(pane) and !pane.trail.held; } +/// The reading pane that is held pane `owner`'s reader, if it has one. +pub fn readerOf(p: *const Pardes, owner: *const Pane) ?usize { + for (p.panes, 0..) |slot, id| { + const r = slot orelse continue; + if (r == owner or !isFile(r) or r.trail.held or r.trail.n == 0) continue; + if (r.trail.steps[0] == .owner and r.trail.steps[0].owner == owner.serial) return id; + } + return null; +} + +/// A new reader's trail: its owner, then where it opened. +pub fn reader(owner: u32, path: []const u8, at: Spot) Trail { + var t: Trail = .{}; + push(&t, .{ .owner = owner }); + if (placeOf(path, at.line, at.col)) |s| push(&t, s); + t.cur = t.n - 1; + return t; +} + +/// A place as a step, null when its path does not fit one. +fn placeOf(path: []const u8, line: usize, col: usize) ?Step { + if (path.len > max_text) return null; + var at: Place = .{ .line = std.math.lossyCast(u32, line), .col = std.math.lossyCast(u32, col) }; + at.path.set(path); + return .{ .place = at }; +} + +/// Where `pane` is now, as a step. +fn here(pane: *const Pane) ?Step { + const f = pane.file orelse return null; + return placeOf(f.path, @as(usize, @intCast(@max(0, pane.body.cur_row))) + 1, @as(usize, @intCast(@max(0, pane.body.cur_col))) + 1); +} + +fn samePlace(s: Step, path: []const u8, line: usize) bool { + return s == .place and s.place.line == line and std.mem.eql(u8, s.place.path.slice(), path); +} + +/// `s` as the newest step, the oldest that is not the owner dropped when +/// the trail is full. +fn push(t: *Trail, s: Step) void { + if (t.n == max_steps) { + const first: usize = @intFromBool(t.steps[0] == .owner); + std.mem.copyForwards(Step, t.steps[first .. max_steps - 1], t.steps[first + 1 ..]); + t.n -= 1; + t.cur -|= 1; + } + t.steps[t.n] = s; + t.n += 1; +} + +/// Step reading pane `id` to `path` at `at` (§6.2): a place already on its +/// trail is gone back or forward to, never held twice; anything else is a +/// new step, which drops the forward steps. The pane's slot after it: a +/// step to another file is a new pane in its place (`replace`). +pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { + const pane = p.panes[id].?; + const t = &pane.trail; + // Where it is already: no step. + if (here(pane)) |was| if (samePlace(was, path, at.line)) return show(p, id, path, at); + for (t.steps[0..t.cur], 0..) |s, i| if (samePlace(s, path, at.line)) return go(p, id, @intCast(i)); + if (t.n > t.cur + 1) for (t.steps[t.cur + 1 .. t.n], t.cur + 1..) |s, j| if (samePlace(s, path, at.line)) return go(p, id, @intCast(j)); + const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong; + // Where it was: the current step's place, or a first one. + if (here(pane)) |was| { + if (t.n > t.cur) { + t.n = t.cur + 1; + t.steps[t.cur] = was; + } else push(t, was); + } else t.n = t.cur; + push(t, to); + t.cur = t.n - 1; + return show(p, id, path, at); +} + +/// Go to step `i` of reading pane `id`'s trail, back or forward (§6.4): +/// where it is now becomes the step it leaves, the ones between stay. +pub fn go(p: *Pardes, id: usize, i: u8) !usize { + const pane = p.panes[id].?; + const t = &pane.trail; + if (i >= t.n or t.steps[i] != .place) return id; + const s = t.steps[i]; + if (t.n > t.cur) if (here(pane)) |was| { + t.steps[t.cur] = was; + }; + t.cur = i; + return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col }); +} + +/// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved +/// in the file it shows, or a new pane on `path` in its place, its walk +/// with it. A line past the new file's end is a miss that changes nothing. +fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { + const pane = p.panes[id].?; + if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) { + look.clearNavigationSelection(p, pane); + look.focusPaneLine(p, id, at, .center); + return id; + }; + const free = p.freeSlot() orelse return error.NoPaneSlots; + const nt = try panes.File.open(p, free, path, at.line); + // Refused: closed at the step's end, never placed (Pardes.unplaced). + errdefer { + p.unplaced.set(free); + nt.vweight = 0; + } + if (at.line > panes.File.nlines(p.gpa, &nt.file.?)) return error.LineMissing; + nt.trail = pane.trail; + // Before the layout gives its place away: its file is told closed + // while it is still in its slot. + try panes.deinitPane(p, pane); + layout.replacePane(p, id, free); + p.panes[id] = null; + layout.compute(p); + look.focusPaneLine(p, free, at, .keep); + // Its line half the body's rows down, as a look's new pane has it. + const rows = @max(1, p.view().rects[free].h -| pardes.BOX_H); + panes.File.setTop(nt, panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, rows / 2)).to); + return free; +} + /// Pane `id` held (§6.5): Keep, or an edit. It no longer walks, so the /// walk leaves its trail (places, lists, its owner, forward steps); words /// about its own text (a search, a recipe) stay. The next jump from its @@ -164,3 +284,135 @@ test "Keep holds a reading pane; a scratch and a listing are never reading" { const listing = p.panes[p.view().active].?; try std.testing.expect(listing.file.?.listing != null and !reading(p, listing)); } + +/// A session over three files of 100 lines in a directory of its own, +/// search.zig, rank.zig and place.zig; search.zig open and edited (held) +/// in pane `held`, under the session's first pane. +const Fixture = struct { + p: *Pardes, + tmp: std.testing.TmpDir, + dir_buf: [4096]u8 = undefined, + dir: []const u8 = "", + held: usize = 0, + + fn init(f: *Fixture, rows: u16) !void { + f.tmp = std.testing.tmpDir(.{}); + errdefer f.tmp.cleanup(); + var text: [100 * 9]u8 = undefined; + var w: std.Io.Writer = .fixed(&text); + for (1..101) |n| try w.print("line {d}\n", .{n}); + for ([_][]const u8{ "search.zig", "rank.zig", "place.zig" }) |name| + try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = w.buffered() }); + f.dir = f.dir_buf[0..try f.tmp.dir.realPath(std.testing.io, &f.dir_buf)]; + f.p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = rows }); + errdefer f.p.deinit(); + _ = try f.p.setTestFile("scratch\n"); + f.p.settings.jumps = .@"new-pane"; + f.look(0, "search.zig", 88); + f.p.settings.jumps = .walk; + f.held = f.p.view().active; + typeKeys(f.p, "ix"); + f.p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + f.p.sync(); + } + + fn deinit(f: *Fixture) void { + f.p.deinit(); + f.tmp.cleanup(); + } + + /// A Look from pane `id` at `name:line` in the fixture's directory. + fn look(f: *Fixture, id: usize, name: []const u8, line: usize) void { + var buf: [4096 + 64]u8 = undefined; + pardes.look.lookAt(f.p, id, std.fmt.bufPrint(&buf, "{s}/{s}:{d}", .{ f.dir, name, line }) catch unreachable); + f.p.sync(); + } + + fn active(f: *Fixture) *Pane { + return f.p.panes[f.p.view().active].?; + } + + /// The active pane's file's name and line, as `rank.zig:12`. + fn at(f: *Fixture, buf: []u8) []const u8 { + const pane = f.active(); + return std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(pane.file.?.path), pane.body.cur_row + 1 }) catch unreachable; + } +}; + +test "a jump from a held pane steps its reader, made under it with half its rows; the reader walks in place, and a place on its trail is gone back to, never held twice" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const held = f.p.panes[f.held].?; + try std.testing.expect(!reading(f.p, held)); + const before = f.p.view().rects[f.held]; + var buf: [64]u8 = undefined; + // g d on rank: its reader, under it, half its rows. + f.look(f.held, "rank.zig", 12); + const r1 = f.p.view().active; + try std.testing.expect(r1 != f.held); + try std.testing.expectEqualStrings("rank.zig:12", f.at(&buf)); + try std.testing.expectEqual(held.serial, f.active().trail.steps[0].owner); + const col = layout.findPane(f.p, f.held).?; + try std.testing.expectEqual(col.col, layout.findPane(f.p, r1).?.col); + try std.testing.expectEqual(col.idx + 1, layout.findPane(f.p, r1).?.idx); + try std.testing.expect(f.p.view().rects[f.held].h <= before.h / 2 + 1); + // Look at place.zig:8 in the reader, from line 14: the reader walks. + typeKeys(f.p, "2j"); + f.look(r1, "place.zig", 8); + const r2 = f.p.view().active; + try std.testing.expect(f.p.panes[r1] == null or r2 == r1); + try std.testing.expectEqualStrings("place.zig:8", f.at(&buf)); + try std.testing.expectEqual(layout.findPane(f.p, f.held).?.idx + 1, layout.findPane(f.p, r2).?.idx); + // g d on Span, from line 9: one more step in the same file. + typeKeys(f.p, "j"); + f.look(r2, "place.zig", 40); + try std.testing.expectEqual(r2, f.p.view().active); + try std.testing.expectEqualStrings("place.zig:40", f.at(&buf)); + const t = &f.active().trail; + try std.testing.expectEqual(@as(u8, 4), t.n); + try std.testing.expectEqual(@as(u8, 3), t.cur); + try std.testing.expectEqual(@as(u32, 14), t.steps[1].place.line); + try std.testing.expectEqual(@as(u32, 9), t.steps[2].place.line); + // The next jump from the held pane lands in the same reader. + f.look(f.held, "rank.zig", 30); + const r3 = f.p.view().active; + try std.testing.expectEqualStrings("rank.zig:30", f.at(&buf)); + try std.testing.expectEqual(held.serial, f.active().trail.steps[0].owner); + var readers: usize = 0; + for (f.p.panes) |slot| if (slot) |pane| { + readers += @intFromBool(pane.trail.n > 0 and pane.trail.steps[0] == .owner); + }; + try std.testing.expectEqual(@as(usize, 1), readers); + // A Look at a place on its trail goes back to it: nothing pushed. + f.look(r3, "rank.zig", 14); + try std.testing.expectEqualStrings("rank.zig:14", f.at(&buf)); + try std.testing.expectEqual(@as(u8, 1), f.active().trail.cur); + try std.testing.expectEqual(@as(u8, 5), f.active().trail.n); +} + +test "a Look from inside the reader at a file its held pane shows focuses the held pane and replaces nothing" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + f.look(f.held, "rank.zig", 12); + const reader_id = f.p.view().active; + const reader_pane = f.active(); + f.look(reader_id, "search.zig", 89); + try std.testing.expectEqual(f.held, f.p.view().active); + try std.testing.expectEqual(@as(i32, 88), f.active().body.cur_row); + try std.testing.expectEqual(reader_pane, f.p.panes[reader_id].?); + try std.testing.expectEqualStrings("rank.zig", std.Io.Dir.path.basename(reader_pane.file.?.path)); +} + +test "the reader of a held pane too short to halve goes to the bottom of the next column, of the previous one from the last" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(24); + defer f.deinit(); + const col = layout.findPane(f.p, f.held).?.col; + try std.testing.expect(f.p.view().rects[f.held].h / 2 < f.p.panes[f.held].?.tag_rows + layout.reader_keeps); + try std.testing.expect(layout.insertColumn(f.p, col, false) != null); + f.look(f.held, "rank.zig", 12); + const reader_id = f.p.view().active; + try std.testing.expectEqual(col + 1, layout.findPane(f.p, reader_id).?.col); +} diff --git a/core/layout.zig b/core/layout.zig index 7fa57ee9..bcf057fa 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -860,8 +860,46 @@ fn blankRows(p: *const Pardes, id: usize) u16 { } /// What a new pane is, and who asked: each rule places them differently. -/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane. -pub const NewPane = enum { scratch, fs, shell, doc, command, errors }; +/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane, +/// `reader` a held pane's reader (Trail.zig). +pub const NewPane = enum { scratch, fs, shell, doc, command, errors, reader }; + +/// The body rows a held pane keeps above its reader: with fewer, the +/// reader goes to the next column (pick-ui SPEC §6.1). +pub const reader_keeps = 8; + +/// A reader's place (pick-ui SPEC §6.1): under its held pane `from`, +/// taking half its rows, unless that leaves it fewer than `reader_keeps` +/// body rows; then at the bottom of the next column, the previous one +/// when `from`'s is the last, as New takes the bottom of a column. +fn readerPlace(p: *Pardes, from: usize, id: usize) void { + const v = p.view(); + const c = columnOf(p, from); + const r = v.rects[from]; + if (findPane(p, from) != null and r.h / 2 >= p.panes[from].?.tag_rows + reader_keeps) return splitAt(p, c, id, r.y + r.h / 2); + acmePlace(p, if (c + 1 < v.ncol) c + 1 else c -| 1, null, id); +} + +/// Pane `new` in pane `old`'s place in every view, with its rows: a +/// reader's step to another file (Trail.zig). `old` leaves no layout. +pub fn replacePane(p: *Pardes, old: usize, new: usize) void { + const was = p.panes[old].?; + const now = p.panes[new].?; + now.vweight = was.vweight; + now.collapsed = was.collapsed; + for (0..pardes.views.max) |k| if (now.pv_known & was.pv_known & (@as(u8, 1) << @intCast(k)) != 0) { + now.pv[k].vweight = was.pv[k].vweight; + now.pv[k].collapsed = was.pv[k].collapsed; + }; + for (&p.views) |*slot| { + const v = &(slot.* orelse continue); + for (v.cols[0..v.ncol]) |*col| for (col.panes[0..col.n]) |*k| if (k.* == old) { + k.* = new; + }; + v.rects[new] = v.rects[old]; + if (v.active == old) v.active = new; + } +} /// Put new pane `id` in the layout: every new pane comes through here, as /// acme's makenewwindow places it, and every one but a command pane takes @@ -888,6 +926,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // makenewwindow(nil) for 9P's new (acme.c:877), else (t). .fs => acmePlace(p, acmeColumn(p, from), null, id), .shell, .doc => acmePlace(p, acmeColumn(p, from), asked, id), + .reader => readerPlace(p, from, id), } // No pane is made shorter than its tag and two rows: where the place // chosen has not the room, the column's tallest pane gives it, and diff --git a/core/look.zig b/core/look.zig index ee6debf9..cc3e750f 100644 --- a/core/look.zig +++ b/core/look.zig @@ -20,6 +20,7 @@ const Color = @import("surface.zig").Color; const Pane = panes.Pane; const MAX_PANES = pardes.MAX_PANES; const Layer = @import("Layer.zig"); +const Trail = @import("Trail.zig"); const TagHit = pardes.TagHit; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; @@ -1164,14 +1165,14 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { // own clean start would collapse its dot (and the looker's) before the // address ever read it, so `f:/re/` again would find the same match. var realbuf: [4096]u8 = undefined; - const open: ?usize = if (path.len == 0) null else switch (resolveLookTarget(p, id, path, &realbuf)) { + const there: ?usize = if (path.len == 0) null else switch (resolveLookTarget(p, id, path, &realbuf)) { .pane => |t| if (t.id < MAX_PANES and p.panes[t.id] != null) t.id else null, else => null, }; // `@p<serial>:<address>`: that pane, or, not open, a miss said as one. const by_serial = std.mem.startsWith(u8, path, config.pane_addr); - if (by_serial and open == null) return missed(p, id, "no pane {s}", .{path[0..@min(path.len, 32)]}); - if (open) |o| target = o else if (path.len > 0) { + if (by_serial and there == null) return missed(p, id, "no pane {s}", .{path[0..@min(path.len, 32)]}); + if (there) |o| target = o else if (path.len > 0) { // A path that names nothing to open: the whole of what was written // is looked for, as `zzq:2` is, and a miss quotes it as written. if (!by_serial and resolveLookTarget(p, id, path, &realbuf) == .none) @@ -1189,7 +1190,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { } const pane = p.panes[target] orelse return; const f = pane.file orelse { - if (pane.addon != null) return lookKind(p, id, target, expr, open == null and target != id); + if (pane.addon != null) return lookKind(p, id, target, expr, there == null and target != id); if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr); // Named as the pane is, the bare `:addr` (path empty) included. var serial_name: [32]u8 = undefined; @@ -1206,7 +1207,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { 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 opened_here = there == null and target != id; 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`. @@ -1497,6 +1498,90 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, } } +/// Where a jump lands: in the pane it walks (`replace`), or always in a +/// new pane under the asking one (`below`, as `Jumps new-pane` opens one). +pub const How = enum { replace, below }; + +/// What a jump did: nothing (refused, said), showed it in a pane there +/// was, or opened a pane for it, which a miss of its line closes again. +pub const Landed = union(enum) { none, shown, opened: usize }; + +/// A jump from pane `from` to `path` at `at`, the keyboard with it: a +/// Look at a place, a definition, an error's place, a list's row (pick-ui +/// SPEC §6.1). With `Jumps walk`: a held pane showing the file is focused +/// and nothing replaced; the asking pane showing it moves in it (a step +/// when it is reading); a reading pane steps in place, a held one steps +/// its reader (Trail.zig), made under it on its first jump. With +/// `Jumps new-pane` as before the walk: a pane showing the file focused, +/// else a new one. +pub fn open(p: *Pardes, from: usize, path: []const u8, at: Spot, how: How) Landed { + if (how == .replace and p.settings.jumps == .walk and path.len <= Trail.max_text and p.panes[from] != null) return walk(p, from, path, at); + if (how == .replace and focusPaneByPath(p, path, at)) return .shown; + return if (openNew(p, from, path, at, .doc)) |free| .{ .opened = free } else .none; +} + +fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed { + const src = p.panes[from].?; + for (p.panes, 0..) |slot, k| { + const held = slot orelse continue; + if (k == from or !Trail.isFile(held) or Trail.reading(p, held) or !std.mem.eql(u8, held.file.?.path, path)) continue; + clearNavigationSelection(p, held); + focusPaneLine(p, k, at, .center); + return .shown; + } + const reads = Trail.reading(p, src); + if (!reads and if (src.file) |f| std.mem.eql(u8, f.path, path) else false) { + clearNavigationSelection(p, src); + focusPaneLine(p, from, at, .center); + return .shown; + } + const into = if (reads) from else Trail.readerOf(p, src) orelse { + const free = openNew(p, from, path, at, .reader) orelse return .none; + p.panes[free].?.trail = Trail.reader(src.serial, path, at); + return .{ .opened = free }; + }; + _ = Trail.step(p, into, path, at) catch |err| { + switch (err) { + error.LineMissing => missedLine(p, from, path, at.line), + error.NoPaneSlots => p.reportError(.at(from), "look", err), + else => lookOpenFailed(p, from, path, err), + } + return .none; + }; + return .shown; +} + +/// `path` opened at `at` in a new pane placed as `kind` places one from +/// `from`, its line half its body's rows down; null when it is not +/// (refused, said). +fn openNew(p: *Pardes, from: usize, path: []const u8, at: Spot, kind: layout.NewPane) ?usize { + const v = p.view(); + const free = p.freeSlot() orelse { + p.reportError(.at(from), "look", error.NoPaneSlots); + return null; + }; + const nt = panes.File.open(p, free, path, at.line) catch |err| { + lookOpenFailed(p, from, path, err); + return null; + }; + nt.body.cur_col = columnOn(nt, nt.body.cur_row, at.col); + const failures = p.fs.failures; + layout.placeNew(p, from, from, free, kind); + // Refused a place: that is the look's one failure, not a miss of its + // line too. + if (p.fs.failures != failures) return null; + layout.compute(p); + // Its line half the body's rows down, a wrapped line's rows above it + // counted. + const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; + panes.File.setTop(nt, centered); + if (at.end_line != 0) { + selectSpan(p, nt, at); + panes.File.setTop(nt, centered); + } + return free; +} + fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { const target = openPaneTarget(p, path, at) orelse return false; clearNavigationSelection(p, p.panes[target.pane.id].?); @@ -1654,6 +1739,16 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // A directory's pane, looked at again: read again. if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id); const before = v.active; + // A file's pane found by its path, not named `@pN`: a jump to + // the file, which walks (open). + if (p.settings.jumps == .walk and Trail.isFile(target) and !std.mem.startsWith(u8, pl.path, config.pane_addr)) { + switch (open(p, id, target.file.?.path, t.at, .replace)) { + .none => {}, + .shown => settleLine(p, id, trimmed, t.at, before, null), + .opened => |free| settleLine(p, id, trimmed, t.at, before, free), + } + return; + } clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); settleLine(p, id, trimmed, t.at, before, null); @@ -1673,34 +1768,15 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { .file => |target| { // An open pane on this path too short for the line: a miss that // touches nothing. - if (openPaneTarget(p, target.path, target.at)) |open| if (p.panes[open.pane.id].?.file) |*f| + if (openPaneTarget(p, target.path, target.at)) |there| if (p.panes[there.pane.id].?.file) |*f| if (target.at.line > panes.File.nlines(p.gpa, f)) return missedLine(p, id, target.path, target.at.line); - // focus an existing pane on this path (rescrolled), else open const before = v.active; - var opened: ?usize = null; - if (!focusPaneByPath(p, target.path, target.at)) { - const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots); - const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| - return lookOpenFailed(p, id, target.path, err); - nt.body.cur_col = columnOn(nt, nt.body.cur_row, target.at.col); - const failures = p.fs.failures; - layout.placeNew(p, id, id, free, .doc); - // Refused a place: that is the look's one failure, not a - // miss of its line too. - if (p.fs.failures != failures) return; - layout.compute(p); - // Its line half the body's rows down, a wrapped line's - // rows above it counted. - const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; - panes.File.setTop(nt, centered); - if (target.at.end_line != 0) { - selectSpan(p, nt, target.at); - panes.File.setTop(nt, centered); - } - opened = free; + switch (open(p, id, target.path, target.at, .replace)) { + .none => {}, + .shown => settleLine(p, id, target.path, target.at, before, null), + .opened => |free| settleLine(p, id, target.path, target.at, before, free), } - settleLine(p, id, target.path, target.at, before, opened); }, .kind => |target| { var place: [41]u8 = undefined; |
