diff options
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/src/Query.zig b/src/Query.zig index 9865001b..749a5245 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -25,8 +25,7 @@ //! rewrites line 1 on its own; zero hits is a state (`0` in the tag). //! Enter lands on the current hit and freezes the rows into ordinary text; //! Esc while typing puts every view back and closes the pane (or brings a -//! reused pane's frozen rows back); Del closes it. One per owner, reused -//! (SearchPane reuse|new). +//! reused pane's frozen rows back); Del closes it. One per owner, reused. const Query = @This(); const std = @import("std"); @@ -202,7 +201,7 @@ fn freeSaved(gpa: std.mem.Allocator, s: Saved) void { } /// The owner's query pane (attached to it, or left where it was by -/// SearchPane new): the one a later search from it reuses. +/// Unattach): the one a later search from it reuses. pub fn ofOwner(p: *Pardes, owner_serial: u32) ?usize { var found: ?usize = null; for (p.panes, 0..) |slot, i| { @@ -243,8 +242,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo const line = std.mem.concat(p.scratch.allocator(), u8, &.{ wordOf(source), if (source == .text) "" else " ", arg }) catch return; var id: usize = undefined; const existing = ofOwner(p, owner.serial); - if (existing != null and (p.settings.search_pane == .reuse or existing.? == from)) { - id = existing.?; + if (existing) |reused| { + id = reused; const rp = p.panes[id].?; const q = rp.query.?; // Its frozen rows, kept for an Esc to bring back. @@ -254,20 +253,12 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo const new = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return; File.setContent(p, f, new); q.reset(p); - if (p.finder.column(p)) |fc| if (layout.findPane(p, id)) |at| if (at.col == fc) p.finder.raise(p, id); if (rp.collapsed) layout.toggleCollapse(p, id); // A source that previews gets its +Preview now, at the key that // asked, not under the typing later. if (previews(source) and previewOf(p, id) == null) - _ = makePreview(p, id, @max(pardes.BOX_H, rp.tag_rows) + p.settings.search_rows, layout.groupRoot(p, id)); - } else { - if (existing) |old| { - // SearchPane new: the last one stays where it is, a result of - // its own; its places are the new one's to feed. - p.panes[old].?.attached_to = null; - } - id = create(p, owner_id, line, source) orelse return; - } + _ = makePreview(p, id, @max(pardes.BOX_H, rp.tag_rows) + born_rows, layout.groupRoot(p, id)); + } else id = create(p, owner_id, line, source) orelse return; // Every view as the search found it, for Esc to put back. owner.places.remember(p, owner); // Before the first key: a names source lists every candidate at once. @@ -277,8 +268,12 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo if (focus) toLineOne(p, id) else p.active = from; } -/// A new query pane under pane `owner_id`, `rows` of the owner's rows (the -/// SearchRows setting), its +Preview under it when `source` can need one. +/// The body rows a query pane is born with under its line 1 (and its +/// +Preview with): it never resizes itself after. +pub const born_rows: u16 = 8; + +/// A new query pane under pane `owner_id`, `born_rows` of the owner's rows, +/// its +Preview under it when `source` can need one. fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize { const owner = p.panes[owner_id] orelse return null; const free = p.freeSlot() orelse { @@ -298,14 +293,14 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize }; q.* = .{ .owner = owner.serial }; np.query = q; - const body: u16 = 1 + p.settings.search_rows; + const body: u16 = 1 + born_rows; const tag = @max(pardes.BOX_H, np.tag_rows); const with_preview = previews(source); // The preview, made right after, takes its own rows from the owner: // when the owner has not the rows for both, they share what it has, so // the group is whole from the first key and nothing moves later. var want: u16 = tag + body; - var preview_rows: u16 = tag + p.settings.search_rows; + var preview_rows: u16 = tag + born_rows; if (with_preview) { layout.compute(p); const spare = p.rects[owner_id].h -| layout.minRows(p, owner_id); @@ -315,13 +310,7 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize preview_rows = spare -| want; } } - if (p.settings.search_place == .column) { - // On top of the finder column at the right edge (Finder.zig), the - // older query panes folded under it; its preview under it there. - if (!p.finder.place(p, free) and !layout.attachFrom(p, owner_id, free, want, owner_id)) exec.placeNew(p, owner_id, owner_id, free, .doc); - if (with_preview) _ = makePreview(p, free, p.rects[free].h / 2, free); - return free; - } else if (!layout.attachFrom(p, owner_id, free, want, owner_id)) { + if (!layout.attachFrom(p, owner_id, free, want, owner_id)) { // An owner too short to give a query pane its rows: placed as any // new pane is, the one place a search moves another pane. exec.placeNew(p, owner_id, owner_id, free, .doc); @@ -1937,8 +1926,7 @@ pub fn cancel(p: *Pardes, id: usize) void { if (owner_id) |oid| p.active = oid; return; } - // Attached, its rows go back to its owner; in the finder column, to its - // own column's. + // Attached, its rows go back to its owner; else to its own column's. const attached = layout.ownerOf(p, id) != null; if (owner_id) |oid| { p.removePane(id, if (attached) oid else null) catch {}; @@ -2427,7 +2415,7 @@ test "Grep: lines of the files under the owner's directory, under their file; Al try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, all, "twice")); } -test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a declaration; SearchPane new leaves the last where it is" { +test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a declaration" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); const pane = try p.setTestFile("const alpha = 1;\nfn beta() void {\n _ = alpha;\n}\nfn gamma() void {}\n"); @@ -2463,13 +2451,6 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); _ = other; - // SearchPane new: the frozen one stays, unattached; a new one under the owner - p.settings.search_pane = .new; - typeKeys(p, "/"); - const nid = queryPane2(p, sid).?; - try std.testing.expect(nid != sid); - try std.testing.expect(p.panes[sid].?.attached_to == null); - try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, nid)); } fn queryPane2(p: *Pardes, not: usize) ?usize { |
