summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig40
1 files changed, 19 insertions, 21 deletions
diff --git a/core/Query.zig b/core/Query.zig
index 3023cc60..feebb6cd 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -344,7 +344,7 @@ pub fn toLineOne(p: *Pardes, id: usize) void {
t.cur_pinned = true;
rp.query.?.seen_row = 0;
edit.enterInsert(p.editor(), t, .line_end, 1) catch |err| return p.reportError(.at(id), "query", err);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
}
/// The rows' state for a new question: nothing found yet.
@@ -456,7 +456,7 @@ fn makeAllRows(p: *Pardes, id: usize) !void {
// The current one: the first hit row, until a step moves it.
if (q.current == null or q.current.? >= q.items.items.len) q.current = firstHit(q);
countCurrent(q);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
}
/// The names the query matches, best first, `Names.max_rows` of them: each
@@ -533,7 +533,7 @@ fn makeNameRows(p: *Pardes, id: usize) !void {
// The best is current until a step or a click moves it.
q.current = if (shown > 0) 0 else null;
countCurrent(q);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
if (q.current == null) blankPreview(p, id) else showTarget(p, id);
}
@@ -1157,7 +1157,7 @@ fn showPlacesCurrent(p: *Pardes, id: usize) void {
};
// Stepped out of the window the live rows are: made again around it.
if (q.current == null and set.current != null and !q.frozen and set.from == rp.serial) q.made_gen = std.math.maxInt(u64);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
}
fn firstHit(q: *const Query) ?usize {
@@ -1233,7 +1233,7 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
q.more = p.stream.busyFor(rp.serial);
q.current = current orelse firstHit(q);
countGrepCurrent(q);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
if (q.current == null) blankPreview(p, id) else if (!shown) showTarget(p, id);
}
@@ -1326,7 +1326,7 @@ pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) v
if (t.mode == .insert) edit.exitInsert(p.editor(), t);
t.vsel.active = false;
t.nsel = 0;
- caretTo(rp, q.current orelse 0);
+ caretTo(p.settings.tab, rp, q.current orelse 0);
showTarget(p, qid);
}
@@ -1448,7 +1448,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void {
}
}
countCurrent(q);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
}
// ---- the current row ----
@@ -1457,7 +1457,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void {
/// elsewhere, line 1 kept when it can be. Its mark is `paint`'s, drawn
/// from `current`: no selection, so no click, sweep or chord clears it and
/// no B2 or B3 borrows it.
-fn showCurrent(rp: *Pane) void {
+fn showCurrent(tab: u16, rp: *Pane) void {
const q = rp.query orelse return;
if (rp.body.cur_row != 0 and rp.focus == .body) return;
const c = q.current orelse return;
@@ -1465,24 +1465,19 @@ fn showCurrent(rp: *Pane) void {
// Typed into, line 1 stays in view whatever the current row: what you
// type is never scrolled away (the live rows start just before the
// current one, so it sits under line 1). Frozen, the row is scrolled to.
- if (!q.frozen) {
- if (rp.scroll() != 0) rp.scrollBy(-rp.scroll());
- return;
- }
- const off = rp.scroll();
- const shown = off + @as(i32, rp.rows) - 1;
- if (r > shown) rp.scrollBy(r - shown) else if (r < off) rp.scrollBy(r - off);
+ if (rp.file == null) return;
+ if (!q.frozen) return panes.File.setTop(rp, .{ .line = 0 });
+ panes.File.show(tab, rp, r, 0, 0);
}
/// The caret on item `i`'s row, the row in view.
-fn caretTo(rp: *Pane, i: usize) void {
+fn caretTo(tab: u16, rp: *Pane, i: usize) void {
const r: i32 = @intCast(i + 1);
rp.body.cur_row = r;
rp.body.cur_col = 0;
rp.body.cur_pinned = true;
rp.query.?.seen_row = r;
- const off = rp.scroll();
- if (r >= off + @as(i32, rp.rows)) rp.scrollBy(r - off - @as(i32, rp.rows) + 1) else if (r < off) rp.scrollBy(r - off);
+ if (rp.file != null) panes.File.show(tab, rp, r, 0, 0);
}
/// The first of pane `tp`'s places on line `line` (1-based), if any.
@@ -1513,7 +1508,7 @@ fn setCurrent(p: *Pardes, id: usize, i: usize, show: bool) void {
if (tp.places.from == rp.serial and tp.serial == q.owner) q.k = hi + 1 else countCurrent(q);
} else countCurrent(q);
} else countCurrent(q) else countCurrent(q);
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
if (show) showTarget(p, id);
}
@@ -1572,6 +1567,7 @@ fn blankPreview(p: *Pardes, qid: usize) void {
File.setContent(p, f, empty);
f.saved_revision = f.revision;
f.scroll = 0;
+ f.scroll_row = 0;
}
/// Where the current row points, shown with the keyboard left where it is:
@@ -1689,6 +1685,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void
File.setContent(p, f, bytes);
f.saved_revision = f.revision;
f.scroll = 0;
+ f.scroll_row = 0;
f.syntax_dirty = true;
pane.hscroll = 0;
// another file: its own places, found below
@@ -1698,6 +1695,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void
look.clearNavigationSelection(p, pane);
if (at.line == 0 or at.line > File.nlines(p.gpa, f)) {
f.scroll = 0;
+ f.scroll_row = 0;
f.syntax_dirty = true;
pane.body.cur_row = 0;
pane.body.cur_col = 0;
@@ -1917,7 +1915,7 @@ pub fn cancel(p: *Pardes, id: usize) void {
q.frozen = true;
rp.body.cur_row = 0;
rp.body.cur_col = 0;
- showCurrent(rp);
+ showCurrent(p.settings.tab, rp);
// Its places again, as Enter left them.
if (q.source == .text) if (owner_id) |oid| if (parse(q.asked)) |a| {
const owner = p.panes[oid].?;
@@ -1983,7 +1981,7 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool {
// The caret on the rows goes to the current row, as j and k
// would have taken it there.
if (t.cur_row != 0) if (q.current) |c| {
- caretTo(rp, c);
+ caretTo(p.settings.tab, rp, c);
};
return true;
}