diff options
Diffstat (limited to 'core/look.zig')
| -rw-r--r-- | core/look.zig | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/core/look.zig b/core/look.zig index 41c59cf3..c7e0feb9 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1522,6 +1522,9 @@ pub const Landed = union(enum) { none, shown, opened: usize }; /// `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 { + // A file a kind takes (an addon's: a picture, a PDF) is its kind's + // pane, as a Look of it opens (resolve), never its bytes as a text. + if (p.kinds.forPath(path)) |k| return openKind(p, from, path, k, at); 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; @@ -1557,6 +1560,38 @@ fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed { return .shown; } +/// The file at `path`, of kind `kind`, looked at from pane `id`: the pane +/// of it there is focused, else one of its kind opened as a document is +/// placed (layout.placeNew), at `at` when it says a place. +fn openKind(p: *Pardes, id: usize, path: []const u8, kind: u8, at: Spot) Landed { + var place: [41]u8 = undefined; + if (focusPaneByPath(p, path, .{})) { + if (at.line > 0) lookKind(p, id, p.view().active, spotText(at, &place), false); + return .shown; + } + const free = p.freeSlot() orelse { + p.reportError(.at(id), "look", error.NoPaneSlots); + return .none; + }; + const made = Kind.openFile(p, free, kind, path) catch |err| { + lookOpenFailed(p, id, path, err); + return .none; + }; + // One its kind refuses (an image corrupt, truncated, not what its name + // says) is said, a failure, rather than shown blank. + if (made.addon.?.refused.len > 0) { + made.vweight = 0; + p.unplaced.set(free); + var said: Kind.Buf(miss_path_cap + 160) = .{}; + var cut: [miss_path_cap + "…".len]u8 = undefined; + p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(path, &cut), made.addon.?.refused.slice() })); + return .none; + } + layout.placeNew(p, id, id, free, .doc); + if (at.line > 0) lookKind(p, id, free, spotText(at, &place), true); + return .{ .opened = free }; +} + /// `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). @@ -1808,24 +1843,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { }; return missed(p, id, "{s}: the pane its list is of is gone", .{target.path}); } - if (focusPaneByPath(p, target.path, .{})) { - if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false); - return; - } - const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots); - const made = Kind.openFile(p, free, target.kind, target.path) catch |err| - return lookOpenFailed(p, id, target.path, err); - // One its kind refuses (an image corrupt, truncated, not what - // its name says) is said, a failure, rather than shown blank. - if (made.addon.?.refused.len > 0) { - made.vweight = 0; - p.unplaced.set(free); - var said: Kind.Buf(miss_path_cap + 160) = .{}; - var cut: [miss_path_cap + "…".len]u8 = undefined; - return p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() })); - } - layout.placeNew(p, id, id, free, .doc); - if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true); + _ = openKind(p, id, target.path, target.kind, target.at); }, } } |
