summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig45
1 files changed, 40 insertions, 5 deletions
diff --git a/core/File.zig b/core/File.zig
index 8749417f..a94353d5 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -1234,6 +1234,7 @@ fn pageEnd(tab: u16, pane: *Pane) usize {
if (pane.wrap_n == 0) return f.scroll + pane.rows;
const last = (if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n) - 1;
const line: usize = @intCast(pane.wrap_line[last]);
+ if (pane.wrap_col[last] < 0) return @max(line, f.scroll + 1);
if (!pane.body_wrapped or line >= nlines(pane.gpa, f)) return line + 1;
const text = sourceLine(pane, @intCast(line));
const width = wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last];
@@ -1705,7 +1706,8 @@ pub fn visualRow(tab: u16, line: []const u8, col: usize, width: usize) VisualRow
pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 {
geometry(tab, pane);
const out = try arena.alloc(u8, pane.geometry_len);
- const filled = fillBody(tab, out, pane, f, wrapWidth(pane, pane.view.wrap), false);
+ const width = wrapWidth(pane, pane.view.wrap);
+ const filled = if (hasGhosts(pane)) fillBody(true, tab, out, pane, f, width, false) else fillBody(false, tab, out, pane, f, width, false);
std.debug.assert(filled == out.len);
return out;
}
@@ -1749,7 +1751,13 @@ fn mapRows(tab: u16, pane: *Pane, f: *State) usize {
pane.body_wrapped = width > 0;
f.tables.ensure(tab, pane.gpa, f);
prepareContextRows(pane, f);
- return fillBody(tab, null, pane, f, width, true);
+ return if (hasGhosts(pane)) fillBody(true, tab, null, pane, f, width, true) else fillBody(false, tab, null, pane, f, width, true);
+}
+
+/// Whether this view of the pane shows ghost rows (jj.zig): its pinned
+/// changes shown, and some.
+fn hasGhosts(pane: *const Pane) bool {
+ return pane.layers.lanes > 0 and pane.ghosts.len > 0;
}
/// Everything the geometry is made of, hashed: the text (its revision and
@@ -1776,7 +1784,10 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 {
/// Run the file-body row walk. With no destination it is the exact sizing
/// pass; with one it fills that allocation and records the wrapping map.
-fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
+/// `ghosted`: the view shows ghost rows (`Pane.ghosts`), each a row of its
+/// own before the line it stands at, no number, its text cut to the row; a
+/// body with none walks without them.
+fn fillBody(comptime ghosted: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
if (record_wrap) pane.wrap_n = 0;
const prefix_width = gutterWidth(pane);
// Where a number ends: a blank, then the lanes (laneCells), after it.
@@ -1788,12 +1799,35 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
var body_line: usize = f.scroll;
var body_at: usize = 0;
var written: usize = 0;
+ // The first ghost row at or below the top line.
+ var ghost: usize = 0;
+ if (ghosted) while (ghost < pane.ghosts.len and pane.ghosts[ghost].at < f.scroll) {
+ ghost += 1;
+ };
for (0..if (pane.body_rows > 0) pane.body_rows else pane.rows) |i| {
if (i > 0) {
if (dst) |out| out[written] = '\n';
written += 1;
}
const context = i < pane.context_rows;
+ if (ghosted and !context and body_at == 0 and ghost < pane.ghosts.len and pane.ghosts[ghost].at == body_line) {
+ const g = pane.ghosts[ghost];
+ const said = pane.ghost_text[g.text..][0..g.len];
+ const shown = if (width > 0) said[0..fitEnd(tab, said, 0, width)] else said[modal.graphemeStart(said, @min(@as(usize, @intCast(@max(0, pane.hscroll))), said.len))..];
+ if (record_wrap) {
+ pane.wrap_line[i] = @intCast(body_line);
+ pane.wrap_col[i] = -1 - @as(i32, @intCast(ghost));
+ pane.wrap_pad[i] = 0;
+ pane.wrap_n = @intCast(i + 1);
+ }
+ if (dst) |out| {
+ @memset(out[written..][0..prefix_width], ' ');
+ @memcpy(out[written + prefix_width ..][0..shown.len], shown);
+ }
+ written += prefix_width + shown.len;
+ ghost += 1;
+ continue;
+ }
const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line;
const at = if (context) 0 else body_at;
const text = if (row < total) sourceLine(pane, @intCast(row)) else "";
@@ -1811,7 +1845,7 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len))
else
at;
- if ((width > 0 or pane.context_rows > 0) and record_wrap) {
+ if ((width > 0 or pane.context_rows > 0 or ghosted) and record_wrap) {
pane.wrap_line[i] = @intCast(row);
pane.wrap_col[i] = @intCast(cut);
pane.wrap_pad[i] = @intCast(pad);
@@ -1957,6 +1991,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
limit = line.len;
} else {
if (vr >= pane.wrap_n) break;
+ if (pane.wrap_col[vr] < 0) continue;
const lrow: usize = @intCast(@max(0, pane.wrap_line[vr]));
if (lrow >= total) break;
base = lineStart(p.gpa, f, lrow);
@@ -2104,7 +2139,7 @@ pub fn paintWordSelection(
var vr: i32 = 0;
while (vr + @as(i32, pane.tag_rows) < @as(i32, r.h)) : (vr += 1) {
const here = pane.wrapAt(p.settings.tab, vr);
- if (here.line != row) continue;
+ if (here.line != row or here.ghost) continue;
var hi = word_hi;
const next = pane.wrapAt(p.settings.tab, vr + 1);
if (next.line == row) hi = @min(hi, next.at);