summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig22
1 files changed, 18 insertions, 4 deletions
diff --git a/core/File.zig b/core/File.zig
index a94353d5..347f4809 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -19,6 +19,7 @@ const locations = @import("locations.zig");
const Colors = @import("colors.zig");
const Tables = @import("Tables.zig");
const Stream = @import("Stream.zig");
+const jj = @import("jj.zig");
const Pane = panes.Pane;
const Output = panes.Output;
const Mini = panes.mini;
@@ -399,7 +400,7 @@ pub fn renderedLineDisplayCol(tab: u16, pane: *const Pane, row: i32, line_text:
return prefix +| rawDisplayCol(tab, line_text[prefix..], byte_col - prefix);
}
-fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
+pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
var end = start;
var used: usize = 0;
while (used < width and end < text.len) {
@@ -757,7 +758,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
};
reportEdit(p, f, off, len, bytes);
// A pinned change's per-line values ride with the lines (jj.zig).
- if (p.changes.answers.items.len > 0) @import("jj.zig").edited(p, f, off, len, bytes);
+ if (p.changes.answers.items.len > 0) jj.edited(p, f, off, len, bytes);
if (f.mini) |*mini| mini.deinit(p.gpa);
f.mini = null;
if (f.line_starts.len > 0) shiftIndex(p.gpa, f, off, len, bytes);
@@ -1659,7 +1660,7 @@ fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void {
/// The path a text's language is known by: a file at a revision's
/// (jj.zig) without its `@rev`.
pub fn langPath(f: *const State) []const u8 {
- return if (@import("jj.zig").of(f)) |r| r.path else f.path;
+ return if (jj.of(f)) |r| r.path else f.path;
}
pub fn supportsContext(pane: *const Pane) bool {
@@ -1686,6 +1687,12 @@ fn prepareContextRows(pane: *Pane, file: *State) void {
pub fn wrapWidth(pane: *const Pane, wrap: bool) usize {
if (!wrap or pane.rows > pane.wrap_line.len) return 0;
+ return bodyWidth(pane);
+}
+
+/// The cells a body row has for text after the gutter (and a cell for a
+/// wrapped line's marker).
+pub fn bodyWidth(pane: *const Pane) usize {
return @max(1, @as(usize, pane.cols -| gutterWidth(pane)) -| 1);
}
@@ -1813,7 +1820,14 @@ fn fillBody(comptime ghosted: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State
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))..];
+ var fit: [jj.row_max]u8 = undefined;
+ // A description is one compact row whatever the scroll.
+ const shown = if (g.kind == .description)
+ jj.fitted(tab, said, bodyWidth(pane), &fit)
+ else 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));