diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-24 13:11:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-24 13:27:54 -0300 |
| commit | 9299281492d63e549ab274034efb59ab4e9d96f6 (patch) | |
| tree | 326e55f07d422adf7fd4e9037107c22bfe70ae6e | |
| parent | 1af098381515fbe3a4fe678cd023c7fd74418ae1 (diff) | |
| download | pardes-9299281492d63e549ab274034efb59ab4e9d96f6.tar.gz pardes-9299281492d63e549ab274034efb59ab4e9d96f6.zip | |
Search converge 6/6: SearchPlace column, the finder column at the right edge holding the query panes; n/N in a frozen query pane; the design doc
| -rw-r--r-- | docs/search-proto-converge.md | 183 | ||||
| -rw-r--r-- | src/Finder.zig | 240 | ||||
| -rw-r--r-- | src/Query.zig | 27 | ||||
| -rw-r--r-- | src/exec.zig | 15 | ||||
| -rw-r--r-- | src/layout.zig | 40 | ||||
| -rw-r--r-- | src/pardes.zig | 18 |
6 files changed, 503 insertions, 20 deletions
diff --git a/docs/search-proto-converge.md b/docs/search-proto-converge.md new file mode 100644 index 00000000..4c7b7006 --- /dev/null +++ b/docs/search-proto-converge.md @@ -0,0 +1,183 @@ +# Search, converged: the query pane + +The design the twelve prototypes added up to (CONVERGE.md), built as the +product in six changes. One pane kind does all searching: the **query +pane**, a `+Search` attached under the pane that asked (its *owner*), whose +body's line 1 is the query, typed into, and whose rows below are made live +from a source. The owner shows the set in its own text (its **places**: +tints, rail ticks, the current one selected), and a row that points at a +file no pane shows is shown in a **+Preview** attached under the query +pane. Everything on screen is text in a pane: B1/B2/B3 and the chords work +on all of it, nothing is drawn over anything, and the notice band keeps +only the prompts that are not search. + +## The pieces, and where they came from + +| piece | file | lifted from | +|---|---|---| +| attached panes: a group under its owner, rows from the owner alone, moving/folding/closing with it, seam drag, Dump/Restore, `Unattach` | `src/layout.zig` "Attached panes", `Pane.attached_to` | attached | +| places: every match tinted, rail ticks (B1 on a tick goes there), current selected and in view, smart-case regex, view-first sliced scan, silent wrap | `src/Places.zig`, `Pane.places` | incsearch (MatchSet) | +| the query pane: line 1, its first word the source, live rows, preview, Enter/Esc/Del, reuse, settings | `src/Query.zig`, `Pane.query` | queryline, pick, live, preview, everywhere | +| fuzzy names (files, recent, panes, declarations) | `src/Names.zig` | pick (its scorer, whole) | +| the disk engine: Grep and Find's listing on a worker, rg or the walk, generations, debounce, cap + `More`; and the declarations parse | `src/Stream.zig`, `Pardes.stream` | stream | +| the finder column (`SearchPlace column`) | `src/Finder.zig`, `Pardes.finder` | column | + +## Semantics + +**Line 1's first word names the source**; editing it changes the source. + +| line 1 | searches | keys | +|---|---|---| +| `/pat` | the owner's text, a regex, any case unless a capital | `/`, `*` (keyboard stays) | +| `Find name` | the files below the pane's directory, fuzzy | `SPC f f`, `Find` | +| `Grep text` | their lines, literally, smart case | `SPC f g`, `Grep` | +| `Recent name` | the files opened lately, fuzzy | `SPC f r`, `Recent` | +| `Panes name` | the open panes, fuzzy | `SPC b b`, `Panes` | +| `Symbols name` | the owner's declarations, fuzzy | `SPC s s` | +| `All pat` | every open pane's text, rows under `@pN name (count)` | `SPC /` | +| `Refs`, `Def`, `Impl`, `Diagnostics` | the language server's lists | `gr`, `gd`, `gi`, `]d`, ... | + +`Search <line 1>` is the builtin under the three argument paths +(`config.leader_args`, pick's table). + +**Rows look like Callstack's**: a gutter line number, the hit's line with +the match tinted (every match on a line tinted, one row a line), under the +declaration it is in (once a parse exists, see below), under the file +(Grep, the LSP lists), under `@pN name (count)` in serial order (All). +B3 on a row's line number looks at its address; B3 on its code is a word +Look as anywhere; B2 on line 1 runs it again. The pane has no gutter of its +own, and its rows are read-only while live (queryline's clampEdit). + +**Keys** on line 1, typing: Ctrl-n / Ctrl-p (and Down / Up, `config.query_next` +/ `query_prev`) step the current row; Enter lands; Esc cancels. Tab stays the +exec chord. In the pane's normal mode (live or frozen): n / N step its rows, +Enter on a row lands on it. In the owner: n / N step its places, round the +end without a word; with no places (or after an `s` changed the register) +they are helix's register search as before. `]d` / `[d` step the +diagnostics' places once a Diagnostics query fed them. + +**The current row shows its target**, the keyboard staying on line 1: a +place in an open pane's text is selected there and scrolled into view +(remembered for Esc); a file an open pane shows, its line there; any other +file in the +Preview. Never the pointer. + +**Enter** puts the keyboard on the current hit in its pane (the +Preview +promoted in place: same slot, serial, rect, an unattached file pane from +then on), fills `/`, and freezes the rows into ordinary text (tag ` Save +Unattach Del`). A `/` freezes its whole list (every place found first, 2000 +rows at most), a Grep every line it has. **Esc** while typing puts every +view back, clears the places it fed and closes the pane, its rows back to +the owner; a reused pane's frozen rows and their places come back instead. +**Del** closes it; closing the owner closes its group. + +**Nothing moves while you type.** The pane is born at tag + 1 + `SearchRows` +(8) rows out of the owner's rows alone, with its +Preview when the source +can preview (the owner's spare rows split between the two if it is short); +it never resizes, closes or rewrites line 1 by itself, and while typed line +1 never scrolls away (the live rows start two places before the current +one, so it sits under line 1). Zero hits is `0` in the tag. A preview made +later (line 1's word edited to a source that previews) takes rows from the +query pane's own bottom, so line 1 stays put; a reused pane gets its +preview at the key that asked. + +**Settings**: `SearchPlace attached|column`, `SearchPane reuse|new`, +`SearchRows N` (1-100). + +## Storyboards + +Text: `/` in the 1.2 MB stress file (playground `src/layout.zig` x23), +cursor on line 15000. + +| step | the screen | +|---|---| +| `/` | A `+Search` opens under layout.zig, taking 10 of its rows; line 1 reads `/`, the caret after it in insert mode; tag `^ +Search 0 Del`. Nothing else moves. | +| keystroke 1, `p` | Every `p` in the view tinted at once, the rest found a 4 ms slice a frame (the tag `1/38479+` until done); rail ticks fill in; the first `p` at or after the cursor selected in layout.zig (scrolled only if off screen). Rows: the lines holding `p`, each ` 15003 code`, from two before the current one, the current marked as the visited row, a note row above saying how many places come before them. | +| keystroke 2, `a` | `pa`: tints, ticks and rows narrow (`1/10189`); the current is again the first at or after where `/` was pressed, not after the last preview. The pane is the same size, line 1 where it was. | +| Ctrl-n / Ctrl-p | The next / previous `pa` current, selected in layout.zig; `2/10189`. | +| Enter | The keyboard on that `pa`, `pa` in `/`, the rows frozen (the whole list, 2000 rows), tag `+Search 2/10189 Save Unattach Del`; tints and ticks stay while the pane lives. Ctrl-o goes back to where `/` was pressed. | +| `n` | The next `pa` in layout.zig, `3/10189`, its row marked in the +Search. | +| `N` | Back to `2/10189`; from the first, round to the last with no message. | +| Esc (typing) | layout.zig's selection and scroll exactly as at `/`, tints and ticks gone, the +Search closed, its rows back to layout.zig. | + +Files: `SPC f f` from the playground's README.md, whose directory is the +playground's root (the snapshot `find.snap` runs the same steps). + +| step | the screen | +|---|---| +| `SPC f f` | The query pane under the pane with its +Preview under it, both out of that pane's rows; line 1 `Find `; the 15 files below the directory listed at once (rg `--files` on the worker; dot-files like `.fill-section.py` and .gitignore'd ones passed over), the first current; tag `1/15`. | +| keystroke 1, `l` | The names scored fuzzily (pick's scorer: segment starts, basename, camel humps), best first, the matched letters tinted: `src/layout.zig`, `src/locations.zig`, `open-all.sh`, `notes/helix-keys.md`, ...; the best current, its head in the +Preview; tag `1/7`. | +| keystroke 2, `a` | `la`: `src/layout.zig`, `src/locations.zig`; tag `1/2`, layout.zig's head in the preview. Nothing moves. | +| Ctrl-n / Ctrl-p | `src/locations.zig` current, its head in the preview. | +| Enter | The preview becomes `src/locations.zig`'s pane where it stands (same rect and serial); the list frozen above it. | +| `n` / `N` | In the query pane: the next / previous name current, shown in a new preview under it (or in its pane when open). In the opened file: helix's register search (a list of names has no places in a text). | +| Esc (typing) | The query pane and its preview closed, their rows back to the pane that asked; nothing opened. | + +Grep is Find's twin with rows under each file's name, run once the typing +pauses (80 ms), stopping at 2000 lines with `More` in the tag; hits in an +open file are that pane's places (n/N there). + +## Numbers + +Debug build (what the playground runs), 160x50, each step `update` + a full +render, machine load ~3. Unit tests `zz query timings` / `zz stream +timings` / `places: a big file...` (run with QUERY_TIMES / PLACES_TIMES). + +| what | cost | +|---|---| +| a cursor move and its frame, no search (baseline) | 0.70 ms | +| `/` opens | 1.05 ms | +| a keystroke of `/pane.v` (38 479 -> 276 places) | 3.0-3.5 ms | +| the ticks after it (7-11 of them, scan slice + rows every third) | worst 6.8-7.3 ms | +| an edit in the owner with the frozen pane open (insert `x` + a tick) | 8.3 ms mean, 10.9 worst | +| the same edit with no search | 7.5 ms | +| places' share of an edit on 1.9 MB (one-splice shift) | 0.44 ms | +| the declarations parse of the 1.2 MB file, on the worker | 474 ms, off the loop; worst frame meanwhile 7.5 ms | +| a keystroke once the rows are grouped under declarations | 4.4 ms | +| Grep race test: 2 engines x 12 rounds, a rogue thread pushing the stale generation | every round only B's lines land | + +So the search costs a keystroke ~2.5 ms over a plain frame and an edit +~0.8 ms, in Debug. Three fixes the numbers forced: `Text.primaryRange` +counted lines from the top for a selection's anchor on every call (18% of +a run; now through the line index, which also took the editor's own +insert-mode key on this file from 11.5 to 7.1 ms); live rows are a window +of 100 (the Debug SafeAllocator's stack capture per allocation was 30% at +1000 rows); the keystroke scans only the view. + +## What differs from CONVERGE, and why + +- **Declaration grouping is the worker's.** A tree-sitter parse of the + stress file is 4.8 s in Debug and the owner's "existing tree" exists only + with TreeContext on. The parse runs on the disk engine's worker with a + parser of its own (`syntax.declarationsApart`, cancellable through + tree-sitter's progress callback) and lands in the pane's + `context_declarations` (what sticky headers read); rows stay ungrouped + until then (live's trick). Without workers (tests) only texts under 64 KB + are parsed, on the loop. +- **Places shift on an edit** instead of being found again view-first: + `File.State.splice` records each edit's span, and the places before it + stay, those after move, only the touched lines are searched again. +- **Grep is literal** (smart case): rg's regex dialect is not mvzr's sam + rules (stream's call). `/` and All are regex. +- **All** follows the open panes (selection and scroll, put back on Esc) + rather than previewing a pane that is on screen anyway. +- **Terminals keep the band `/`**, as PDFs do: a terminal's text is no + `File`, and places need one. +- **A list's places feed every open file its rows land in**, not only the + owner (Refs in main.rs, asked from lib.rs: n/N in main.rs step them). +- **The live rows are a window**: 100 rows from two before the current + place; the whole list on Enter. +- A dumped query pane restores as a plain +Search, and a dumped finder + column as a plain column. + +## Rough + +- LookNext / LookPrev do not step query rows (their addresses are in row + metadata, not text). +- Grep rows carry no syntax colours; `/` rows are coloured where the + owner's highlights cover them (zeros elsewhere, so no fragment parse per + refill). +- Rail ticks are not carried over the detached wire (a detached frontend + shows tints, not ticks). +- In a window too short for the group (4 rows), only the query pane's tag + shows. +- The finder column keeps 8 query panes; older ones close. diff --git a/src/Finder.zig b/src/Finder.zig new file mode 100644 index 00000000..a2b8f89f --- /dev/null +++ b/src/Finder.zig @@ -0,0 +1,240 @@ +//! The finder column: where query panes go with `SearchPlace column`, the +//! alternative to attaching them under the pane that asked (lifted from +//! the column prototype, cut to its placement). A column with a role at +//! the right edge: the first search opens it and the other columns give it +//! its share once, each in proportion to its weight; after that no pane +//! outside it moves for a search. Its width is a share of the window, not a +//! column weight (layout.compute), so it opens and closes without rounding +//! anyone's width off. Its panes are a recency stack: the newest query pane +//! on top and open, the older ones folded to their tags. A pane opened +//! from a row goes to the column of the pane the query searches, never in +//! here. Its last pane gone, the column goes and every other is as wide as +//! before it came. The role is the column's serial. +const Finder = @This(); + +const std = @import("std"); +const pardes = @import("pardes.zig"); +const layout = @import("layout.zig"); +const config = @import("config.zig"); +const panes = @import("panes.zig"); +const Pardes = pardes.Pardes; + +/// The finder column's serial (layout.columnSerial); 0 while there is none. +serial: u32 = 0, +/// Its width, in thousandths of the window's: kept while it is closed, so +/// it comes back as wide as it went. +share: u16 = 300, + +/// More query panes than this and the oldest closes: each folded one keeps +/// a tag row. ponytail: a fixed count; size it from the column's rows. +pub const max_results = 8; + +const tag_text = "Finder Delcol"; + +/// The finder column's index, while it is there. +pub fn column(f: *const Finder, p: *const Pardes) ?usize { + if (f.serial == 0) return null; + return layout.columnBySerial(p, f.serial); +} + +/// Its width in cells: its share, leaving every other column MINW; the +/// whole window when it is the only column. +pub fn width(f: *const Finder, p: *const Pardes) u16 { + if (p.ncol <= 1) return p.screen_w; + const others: u32 = @as(u32, config.MINW) * @as(u32, @intCast(p.ncol - 1)); + const most: u32 = @as(u32, p.screen_w) -| others; + const wanted: u32 = @as(u32, p.screen_w) * f.share / 1000; + return @intCast(@min(@max(wanted, config.MINW), @max(most, @min(config.MINW, p.screen_w)))); +} + +/// Query pane `id` goes on top of the finder column, opened at the right +/// edge if there is none; the older ones fold. False when the window has +/// no room for the column (the caller attaches it instead). +pub fn place(f: *Finder, p: *Pardes, id: usize) bool { + const pane = p.panes[id] orelse return false; + const c = f.column(p) orelse f.open(p) orelse return false; + layout.insert(p, c, 0, id); + pane.vweight = 1; + pane.collapsed = false; + f.fold(p, c, id); + // The oldest goes once there are too many: the bottom one, as the top + // is always the newest. + while (p.col_n[c] > max_results) { + const oldest = p.col_panes[c][p.col_n[c] - 1]; + p.removePane(oldest, null) catch break; + } + return true; +} + +/// A finder column at the right edge, empty, its tag its own: the other +/// columns give it its share, each in proportion to its weight. Null when +/// the window has no room for one more column, or narrower columns would +/// leave a pane under its tag and 2 rows. +fn open(f: *Finder, p: *Pardes) ?usize { + if (p.ncol >= pardes.MAX_COLS or p.ncol == 0) return null; + if (p.screen_w < @as(u32, config.MINW) * @as(u32, @intCast(p.ncol + 1))) return null; + const c = p.ncol; + p.col_n[c] = 0; + // Not used for its width (layout.compute), only kept positive for the + // code that halves and joins weights. + p.col_weight[c] = layout.column_weight_unit; + p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; + p.col_tags[c].own = p.gpa.dupe(u8, tag_text) catch null; + p.col_serial[c] = 0; + p.ncol += 1; + f.serial = layout.columnSerial(p, c); + // A narrower column wraps long tags onto more rows: shared out again, + // and where that cannot hold every minimum there is no finder, as + // Newcol is refused. + layout.compute(p); + for (0..p.ncol) |k| if (k != c and !layout.columnAtMinimums(p, k) and !layout.shareColumn(p, k)) { + layout.dropColumnUnannounced(p, c); + f.serial = 0; + layout.compute(p); + return null; + }; + layout.noteColumn(p, "newcol", f.serial); + return c; +} + +/// Fold every pane of finder column `c` but `top` (and what is attached +/// to it, its +Preview) to its tag. +fn fold(f: *const Finder, p: *Pardes, c: usize, top: usize) void { + _ = f; + layout.compute(p); + for (p.col_panes[c][0..p.col_n[c]]) |k| { + const pane = p.panes[k] orelse continue; + if (k == top or layout.groupRoot(p, k) == top) { + pane.collapsed = false; + pane.vweight = 1; + } else if (!pane.collapsed) { + // As Collapse folds it: its weight keeps its height for later. + pane.vweight = @floatFromInt(@max(1, p.rects[k].h)); + pane.collapsed = true; + } + } + layout.compute(p); +} + +/// Query pane `id`, asked again: back on top of the stack, open, the rest +/// folded. Nothing outside the finder column moves. +pub fn raise(f: *Finder, p: *Pardes, id: usize) void { + const c = f.column(p) orelse return; + const at = layout.findPane(p, id) orelse return; + if (at.col != c) return; + if (at.idx != 0) { + // the pane and what is attached to it (its +Preview) move together + const end = layout.groupEnd(p, c, at.idx); + var moved: [pardes.MAX_PANES]usize = undefined; + const n = end - at.idx; + @memcpy(moved[0..n], p.col_panes[c][at.idx..end]); + for (moved[0..n]) |k| layout.removePane(p, k); + for (moved[0..n], 0..) |k, i| layout.insert(p, c, i, k); + } + f.fold(p, c, id); +} + +/// The column a pane asked for from the finder goes in (a row looked at, a +/// command run there): the column of the pane its query searches, else +/// the nearest other. Null when nothing points at the finder. +pub fn away(f: *Finder, p: *Pardes, from: usize, kind: pardes.exec.NewPane) ?usize { + const fc = f.column(p) orelse return null; + const in_finder = if (layout.findPane(p, from)) |at| at.col == fc else false; + const to_last = (kind == .command or kind == .errors) and fc == p.ncol - 1; + if (!in_finder and p.exec_column != fc and !to_last) return null; + if (in_finder) { + const root = layout.groupRoot(p, from); + if (p.panes[root]) |qp| if (qp.query) |q| if (p.paneBySerial(q.owner)) |oid| if (layout.findPane(p, oid)) |at| + if (at.col != fc) return at.col; + } + if (fc > 0) return fc - 1; + if (fc + 1 < p.ncol) return fc + 1; + // The finder is the only column: a document asked from it gets one of + // its own, left of it. + return layout.insertColumn(p, fc, true); +} + +/// The finder column has lost its last pane: it goes, and every other +/// column is as wide as before it came. +pub fn emptied(f: *Finder, p: *Pardes, c: usize) bool { + if (f.column(p) != c or p.col_n[c] != 0) return false; + layout.dropColumn(p, c); + f.serial = 0; + return true; +} + +/// A drag of the border between the finder column and column `other` +/// beside it: the finder's share follows the edge, and `other` takes the +/// difference, every other column keeping its width. +pub fn dragWidth(f: *Finder, p: *Pardes, other: usize, finder_w: u64) void { + const fc = f.column(p) orelse return; + if (p.screen_w == 0) return; + const combined: u64 = p.col_w[fc] + p.col_w[other]; + if (combined < 2 * @as(u64, config.MINW)) return; + const fw = std.math.clamp(finder_w, config.MINW, combined - config.MINW); + f.share = @intCast(@max(1, @min(999, fw * 1000 / p.screen_w))); + var rest_weight: u128 = 0; + var rest_cells: u64 = 0; + for (0..p.ncol) |k| if (k != fc and k != other) { + rest_weight += p.col_weight[k]; + rest_cells += p.col_w[k]; + }; + if (rest_cells > 0) { + const other_cells = combined - fw; + const w = @as(u128, other_cells) * rest_weight / rest_cells; + p.col_weight[other] = @intCast(std.math.clamp(w, 1, layout.max_column_weight)); + } + layout.compute(p); +} + +fn typeKeys(p: *Pardes, text: []const u8) void { + for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); +} + +test "SearchPlace column: query panes stack in a finder column at the right edge, nothing else moves after it opens, and it goes with its last pane" { + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + p.settings.search_place = .column; + const pane = try p.setTestFile("alpha one\nbeta\nalphabet\n"); + p.newScratchBelow(0); + const other = p.active; + p.active = 0; + layout.compute(p); + const before = p.rects; + const width_before = p.col_w[0]; + typeKeys(p, "/"); + const fc = p.finder.column(p).?; + try std.testing.expectEqual(@as(usize, 1), fc); + const first = p.col_panes[fc][0]; + try std.testing.expect(p.panes[first].?.query != null); + // the first search narrows the column once; its panes keep their rows + try std.testing.expect(p.col_w[0] < width_before); + try std.testing.expectEqual(before[0].h, p.rects[0].h); + try std.testing.expectEqual(before[other].h, p.rects[other].h); + typeKeys(p, "alpha"); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expect(pane.places.started); + layout.compute(p); + const opened = p.rects; + // a second search, from the other pane: on top, the first folded + p.active = other; + typeKeys(p, "/"); + const second = p.col_panes[fc][0]; + try std.testing.expect(second != first); + try std.testing.expect(p.panes[first].?.collapsed); + layout.compute(p); + try std.testing.expectEqualDeep(opened[0], p.rects[0]); + try std.testing.expectEqualDeep(opened[other], p.rects[other]); + // Esc: the second closes, the first stays + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[second] == null); + try std.testing.expectEqual(fc, p.finder.column(p).?); + // the first's Del: the column goes, every other as wide as before it + pardes.exec.runBuiltin(p, .Del, first, "", null); + try std.testing.expect(p.finder.column(p) == null); + layout.compute(p); + try std.testing.expectEqual(width_before, p.col_w[0]); + try std.testing.expectEqualDeep(before[0], p.rects[0]); +} diff --git a/src/Query.zig b/src/Query.zig index 3a75a7f5..6374ce42 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -257,6 +257,7 @@ 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. @@ -318,8 +319,11 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize } } if (p.settings.search_place == .column) { - // The finder column (phase 6): until it exists, under the owner. - if (!layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc); + // 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.attach(p, owner_id, free, want)) 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.attach(p, owner_id, free, want)) { // 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. @@ -1727,8 +1731,11 @@ 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. + const attached = layout.ownerOf(p, id) != null; if (owner_id) |oid| { - p.removePane(id, oid) catch {}; + p.removePane(id, if (attached) oid else null) catch {}; p.active = oid; if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col); } else p.removePane(id, null) catch {}; @@ -1772,7 +1779,9 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool { const q = rp.query orelse return false; if (rp.focus != .body) return false; const t = &rp.body; - if (q.frozen) return false; + // Normal mode, live or frozen: n and N step the rows (the current one + // shown where it points, the keyboard staying), Enter on a hit row lands + // on it, as Enter typing does. if (t.mode == .normal) { if (t.normal.prefix != .none or k.ctrl or k.alt or t.normal.count != 0) return false; if (k.cp == 'n' or k.cp == 'N') { @@ -1780,11 +1789,14 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool { return true; } if (hit(k, config.look_key) and t.cur_row > 0) { - land(p, id, @intCast(t.cur_row - 1)); + const i: usize = @intCast(t.cur_row - 1); + if (i >= q.items.items.len or q.items.items[i].kind != .hit) return false; + land(p, id, i); return true; } return false; } + if (q.frozen) return false; if (t.cur_row != 0 or t.mode != .insert or t.reg_wait) return false; if (hit(k, config.escape)) { cancel(p, id); @@ -2003,6 +2015,11 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile defer std.testing.allocator.free(frozen); // the rows: one a line (gamma alpha has one), a gutter number each try std.testing.expect(std.mem.indexOf(u8, frozen, " 1 alpha one\n") != null); + // B3 on a row's line number is its address; on its code, no address + var abuf: [256]u8 = undefined; + const addr = rowAddress(qp, 1, 2, &abuf).?; + try std.testing.expect(std.mem.endsWith(u8, addr, ":1:1")); + try std.testing.expect(rowAddress(qp, 1, qp.file.?.location_rows[1].code_start + 1, &abuf) == null); // n and N in the owner step the same set, round the end silently const logged = p.messages.len; try std.testing.expectEqual(@as(?usize, 0), pane.places.current); diff --git a/src/exec.zig b/src/exec.zig index 2bc1a3e5..142dfef6 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -1197,6 +1197,14 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // No column left (the last one Delcol'd): a pane made from the workspace // tag opens one to go in. _ = layout.firstColumn(p); + // Anything asked from the finder column (a row looked at, a command + // there) goes where its query came from, never into the finder; and + // the rules that take the last column take the last that is not it. + const exec_column = p.exec_column; + defer p.exec_column = exec_column; + const away = p.finder.away(p, from, kind); + if (away) |c| p.exec_column = c; + const finder_column = p.finder.column(p); const asked = if (p.exec_column != null) null else origin; layout.compute(p); const before = p.rects; @@ -1206,9 +1214,10 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // (look.c:921-923, et->col). .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id), // +Errors, a command's output: the last column (util.c:94-98); - // a command run from a column's tag, that column. + // a command run from a column's tag, that column. The finder's + // is never the last column for them. .command => layout.acmePlace(p, p.exec_column orelse p.ncol - 1, null, id), - .errors => layout.acmePlace(p, p.ncol - 1, null, id), + .errors => layout.acmePlace(p, away orelse p.ncol - 1, null, id), // makenewwindow(nil) for 9P's new (acme.c:877), else (t). .fs => layout.acmePlace(p, acmeColumn(p, from), null, id), .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id), @@ -1238,7 +1247,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan var c = p.ncol; while (c > 0) { c -= 1; - if (c == f.col) continue; + if (c == f.col or c == finder_column) continue; for (p.col_panes[c][0..p.col_n[c]]) |k| p.rects[k] = before[k]; layout.snapColWeights(p, c); if (p.col_n[c] == 0) { diff --git a/src/layout.zig b/src/layout.zig index dac0aa7e..8739122c 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -166,6 +166,11 @@ pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void { if (left + 1 >= p.ncol) return; const combined: u64 = p.col_w[left] + p.col_w[left + 1]; + // The finder's edge sets its share (Finder.dragWidth). + if (p.finder.column(p)) |fc| { + if (fc == left + 1) return p.finder.dragWidth(p, left, combined -| left_width); + if (fc == left) return p.finder.dragWidth(p, left + 1, left_width); + } // Too narrow for both to keep MINW: any split would squeeze one away. if (combined < 2 * @as(u64, config.MINW)) return; const width = std.math.clamp(left_width, config.MINW, @max(@as(u64, config.MINW), combined -| config.MINW)); @@ -467,7 +472,12 @@ pub fn dropColumn(p: *Pardes, c: usize) void { pub fn dropColumnUnannounced(p: *Pardes, c: usize) void { std.debug.assert(p.col_n[c] == 0); tagline.exitHeader(p); - if (p.ncol > 1) p.col_weight[if (c > 0) c - 1 else c + 1] +|= p.col_weight[c]; + // The finder's width was its share, no weight: nobody gets one, so the + // others are as wide as before it came. A column whose weight would go + // to the finder gives it to the column on the finder's other side. + const finder = p.finder.column(p); + const heir: ?usize = if (p.ncol <= 1 or finder == c) null else if (c > 0 and finder != c - 1) c - 1 else if (c + 1 < p.ncol and finder != c + 1) c + 1 else if (c > 1) c - 2 else if (c + 2 < p.ncol) c + 2 else null; + if (heir) |h| p.col_weight[h] +|= p.col_weight[c]; p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { @@ -1187,20 +1197,32 @@ pub fn compute(p: *Pardes) void { if (p.ncol == 0) return; keepGroups(p); for (0..p.ncol) |column| _ = columnSerial(p, column); + // The finder column is as wide as its share says (Finder.width), not + // by weight: the others share what it leaves by theirs, so it comes + // and goes and each of them keeps its proportion, none rounded off. + const finder = p.finder.column(p); + const finder_w: u16 = if (finder != null) p.finder.width(p) else 0; + const rest = p.screen_w -| finder_w; var wsum: u128 = 0; - for (0..p.ncol) |c| wsum += p.col_weight[c]; + var last_plain: usize = p.ncol; + for (0..p.ncol) |c| if (finder != c) { + wsum += p.col_weight[c]; + last_plain = c; + }; if (wsum == 0) wsum = 1; // Round cumulative boundaries so widths still sum to the available screen. var prefix: u128 = 0; + var offset: u16 = 0; for (0..p.ncol) |c| { - const last = c + 1 == p.ncol; - const x = columnBoundary(p.screen_w, prefix, wsum); - prefix += p.col_weight[c]; - const end: u16 = if (last) - p.screen_w - else - columnBoundary(p.screen_w, prefix, wsum); + const x = offset + columnBoundary(rest, prefix, wsum); + const end: u16 = if (finder == c) end: { + offset = finder_w; + break :end x + finder_w; + } else end: { + prefix += p.col_weight[c]; + break :end if (c == last_plain) offset + rest else offset + columnBoundary(rest, prefix, wsum); + }; const cw = end -| x; p.col_x[c] = x; p.col_w[c] = cw; diff --git a/src/pardes.zig b/src/pardes.zig index 3ccfee5f..6f30d6ca 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -26,6 +26,7 @@ pub const Registers = @import("Registers.zig"); pub const Macro = @import("Macro.zig"); pub const Pipe = @import("Pipe.zig"); pub const Stream = @import("Stream.zig"); +pub const Finder = @import("Finder.zig"); pub const colors = @import("colors.zig"); pub const Theme = colors.Theme; pub const themes = colors.themes; @@ -490,6 +491,7 @@ test { _ = @import("Query.zig"); _ = @import("Names.zig"); _ = @import("Stream.zig"); + _ = @import("Finder.zig"); } pub const Builtin = builtins.registry.Builtin(); @@ -4386,6 +4388,9 @@ pub const Pardes = struct { col_tags: [MAX_COLS]Text = @splat(.{ .what = .column }), col_serial: [MAX_COLS]u32 = @splat(0), next_column_serial: u32 = 1, + /// The finder column, where query panes stack with SearchPlace column + /// (Finder.zig). + finder: Finder = .{}, global_tag: Text = .{ .what = .workspace }, // derived each sync rects: [MAX_PANES]Rect = @splat(.{}), @@ -5225,14 +5230,19 @@ pub const Pardes = struct { pub fn newColumn(p: *Pardes, from_id: usize) void { // An empty window (Delcol took the last column): its first column. if (layout.firstColumn(p)) |c| return tagline.enterHeader(p, c); - const col = p.keyboardColumn(from_id) orelse return; + const keyboard_col = p.keyboardColumn(from_id) orelse return; + // Asked from the finder: the new column goes left of it, so the + // finder stays at the edge as wide. + const in_finder = p.finder.column(p) == keyboard_col; + const before_finder = in_finder and keyboard_col == 0; + const col = if (in_finder and keyboard_col > 0) keyboard_col - 1 else keyboard_col; // A trial: laying it out gives it a serial (layout.compute), which a // refusal takes back. Every other column has its own already, so // the counter as it is now is the trial's to return to. for (0..p.ncol) |k| _ = layout.columnSerial(p, k); const unspent = p.next_column_serial; // Said, not silently nothing: "no space" is 9ns's word for ENOSPC. - const c = layout.insertColumnUnannounced(p, col, false) orelse { + const c = layout.insertColumnUnannounced(p, col, before_finder) orelse { var said: [96]u8 = undefined; return p.reportFailure(from_id, if (p.ncol >= MAX_COLS) std.fmt.bufPrint(&said, "Newcol: no space for a column: {d} max", .{MAX_COLS}) catch "Newcol: no space for a column" @@ -7224,9 +7234,11 @@ pub const Pardes = struct { const beside = if (emptied) |c| p.besideColumn(c, p.rects[id]) else null; layout.removePane(p, id); p.panes[id] = null; + // The finder's last pane takes the column with it. + const finder_gone = if (emptied) |c| p.finder.emptied(p, c) else false; if (p.active != id) return; p.active = gainer orelse beside orelse p.anyPane() orelse return p.quitEmpty(); - if (emptied) |c| if (!p.header_focus) tagline.enterHeader(p, c); + if (emptied) |c| if (!finder_gone and !p.header_focus) tagline.enterHeader(p, c); } /// Delcol: close column `col` and every pane in it. |
