summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/File.zig b/core/File.zig
index b21dac78..36e014b3 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -334,6 +334,13 @@ pub fn byteAtRowDisplay(tab: u16, pane: *const Pane, row: i32, from_raw: i32, di
return @intCast(byteAtDisplayFrom(tab, line_text, @intCast(@max(0, from_raw)), @intCast(@max(0, display_col))));
}
+/// The slot after a text's last newline: a line the cursor can sit on that
+/// is not there yet. Its gutter shows `~` for a number, as helix's does.
+pub fn endSlot(pane: *const Pane, row: usize) bool {
+ const f = if (pane.file) |*file| file else return false;
+ return row > 0 and row + 1 == f.line_starts.len and f.line_starts[row] == f.content.len;
+}
+
pub fn gutterWidth(pane: *const Pane) u16 {
if (pane.file == null) return 0;
const file = &pane.file.?;
@@ -1734,6 +1741,9 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
if (record_wrap) pane.wrap_n = 0;
const prefix_width = gutterWidth(pane);
const total = nlines(pane.gpa, f);
+ // The slot after the text's last newline, found once: every numbered
+ // row below asks whether it is that one.
+ const end_slot: usize = if (total > 0 and endSlot(pane, total - 1)) total - 1 else std.math.maxInt(usize);
var body_line: usize = f.scroll;
var body_at: usize = 0;
var written: usize = 0;
@@ -1773,7 +1783,9 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
if (at == 0 and prefix.len > 0) {
var lineno = row + 1;
var digit: usize = prefix.len - 1;
- while (true) {
+ if (row == end_slot) {
+ prefix[digit - 1] = '~';
+ } else while (true) {
digit -= 1;
prefix[digit] = '0' + @as(u8, @intCast(lineno % 10));
lineno /= 10;