fix: whitespace rendering on scroll left
This also simplifies the renderer a little.
This commit is contained in:
parent
919d5ee9bb
commit
e3d93da9e6
1 changed files with 41 additions and 37 deletions
|
@ -820,7 +820,7 @@ pub const Editor = struct {
|
||||||
9 => ctx.self.render_tab(c, n, ctx.buf_col),
|
9 => ctx.self.render_tab(c, n, ctx.buf_col),
|
||||||
else => render_egc(c, n, chunk),
|
else => render_egc(c, n, chunk),
|
||||||
};
|
};
|
||||||
const cell_map_val: CellType = switch (chunk[0]) {
|
var cell_map_val: CellType = switch (chunk[0]) {
|
||||||
32 => .space,
|
32 => .space,
|
||||||
9 => .tab,
|
9 => .tab,
|
||||||
else => .character,
|
else => .character,
|
||||||
|
@ -830,50 +830,59 @@ pub const Editor = struct {
|
||||||
self_.render_matches(&ctx.match_idx, ctx.theme, c);
|
self_.render_matches(&ctx.match_idx, ctx.theme, c);
|
||||||
self_.render_selections(ctx.theme, c);
|
self_.render_selections(ctx.theme, c);
|
||||||
|
|
||||||
const advanced = if (ctx.buf_col >= view.col) n.putc(c) catch break else colcount;
|
var advance = colcount;
|
||||||
const new_col = ctx.buf_col + colcount - advanced;
|
if (ctx.buf_col < view.col) {
|
||||||
if (ctx.buf_col < view.col and ctx.buf_col + advanced > view.col)
|
advance = if (ctx.buf_col + advance >= view.col)
|
||||||
n.cursor_move_rel(0, @intCast(ctx.buf_col + advanced - view.col)) catch {};
|
ctx.buf_col + advance - view.col
|
||||||
ctx.buf_col += advanced;
|
else
|
||||||
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = cell_map_val });
|
0;
|
||||||
ctx.x += advanced;
|
}
|
||||||
|
if (ctx.buf_col >= view.col) {
|
||||||
while (ctx.buf_col < new_col) {
|
_ = n.putc(c) catch {};
|
||||||
if (ctx.buf_col >= view.col + view.cols)
|
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = cell_map_val });
|
||||||
break;
|
if (cell_map_val == .tab) cell_map_val = .extension;
|
||||||
|
advance -= 1;
|
||||||
|
ctx.x += 1;
|
||||||
|
n.cursor_move_yx(@intCast(ctx.y), @intCast(ctx.x)) catch {};
|
||||||
|
}
|
||||||
|
while (advance > 0) : (advance -= 1) {
|
||||||
|
if (ctx.x >= view.cols) break;
|
||||||
var cell_ = n.cell_init();
|
var cell_ = n.cell_init();
|
||||||
const c_ = &cell_;
|
const c_ = &cell_;
|
||||||
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
||||||
self_.render_line_highlight_cell(ctx.theme, c_);
|
self_.render_line_highlight_cell(ctx.theme, c_);
|
||||||
self_.render_matches(&ctx.match_idx, ctx.theme, c_);
|
self_.render_matches(&ctx.match_idx, ctx.theme, c_);
|
||||||
self_.render_selections(ctx.theme, c_);
|
self_.render_selections(ctx.theme, c_);
|
||||||
const advanced_ = n.putc(c_) catch break;
|
_ = n.putc(c_) catch {};
|
||||||
ctx.buf_col += advanced_;
|
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = cell_map_val });
|
||||||
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = .extension });
|
if (cell_map_val == .tab) cell_map_val = .extension;
|
||||||
ctx.x += advanced;
|
ctx.x += 1;
|
||||||
|
n.cursor_move_yx(@intCast(ctx.y), @intCast(ctx.x)) catch {};
|
||||||
}
|
}
|
||||||
|
ctx.buf_col += colcount;
|
||||||
chunk = chunk[bytes..];
|
chunk = chunk[bytes..];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leaf.eol) {
|
if (leaf.eol) {
|
||||||
var c = ctx.self.render_eol(n, ctx.theme);
|
if (ctx.buf_col >= view.col) {
|
||||||
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
var c = ctx.self.render_eol(n);
|
||||||
self_.render_line_highlight_cell(ctx.theme, &c);
|
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
||||||
self_.render_matches(&ctx.match_idx, ctx.theme, &c);
|
self_.render_line_highlight_cell(ctx.theme, &c);
|
||||||
self_.render_selections(ctx.theme, &c);
|
self_.render_matches(&ctx.match_idx, ctx.theme, &c);
|
||||||
_ = n.putc(&c) catch {};
|
self_.render_selections(ctx.theme, &c);
|
||||||
var term_cell = render_terminator(n, ctx.theme);
|
_ = n.putc(&c) catch {};
|
||||||
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
var term_cell = render_terminator(n, ctx.theme);
|
||||||
self_.render_line_highlight_cell(ctx.theme, &term_cell);
|
if (ctx.hl_row) |hl_row| if (hl_row == ctx.buf_row)
|
||||||
_ = n.putc(&term_cell) catch {};
|
self_.render_line_highlight_cell(ctx.theme, &term_cell);
|
||||||
n.cursor_move_yx(-1, 0) catch |e| return Buffer.Walker{ .err = e };
|
_ = n.putc(&term_cell) catch {};
|
||||||
n.cursor_move_rel(1, 0) catch |e| return Buffer.Walker{ .err = e };
|
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = .eol });
|
||||||
|
}
|
||||||
ctx.buf_row += 1;
|
ctx.buf_row += 1;
|
||||||
ctx.buf_col = 0;
|
ctx.buf_col = 0;
|
||||||
ctx.cell_map.set_yx(ctx.y, ctx.x, .{ .cell_type = .eol });
|
|
||||||
ctx.y += 1;
|
ctx.y += 1;
|
||||||
ctx.x = 0;
|
ctx.x = 0;
|
||||||
ctx.leading = true;
|
ctx.leading = true;
|
||||||
|
n.cursor_move_yx(@intCast(ctx.y), @intCast(ctx.x)) catch {};
|
||||||
}
|
}
|
||||||
return Buffer.Walker.keep_walking;
|
return Buffer.Walker.keep_walking;
|
||||||
}
|
}
|
||||||
|
@ -1086,16 +1095,11 @@ pub const Editor = struct {
|
||||||
return .{ 1, 1 };
|
return .{ 1, 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fn render_eol(self: *const Self, n: *Plane, theme: *const Widget.Theme) Cell {
|
inline fn render_eol(_: *const Self, n: *Plane) Cell {
|
||||||
const char = whitespace.char;
|
const char = whitespace.char;
|
||||||
var cell = n.cell_init();
|
var cell = n.cell_init();
|
||||||
const c = &cell;
|
const c = &cell;
|
||||||
if (self.render_whitespace == .visible) {
|
_ = n.cell_load(c, char.blank) catch {};
|
||||||
c.set_style(theme.editor_whitespace);
|
|
||||||
_ = n.cell_load(c, char.eol) catch {};
|
|
||||||
} else {
|
|
||||||
_ = n.cell_load(c, char.blank) catch {};
|
|
||||||
}
|
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1117,7 +1121,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
inline fn render_tab(self: *const Self, c: *Cell, n: *Plane, abs_col: usize) struct { usize, usize } {
|
inline fn render_tab(self: *const Self, c: *Cell, n: *Plane, abs_col: usize) struct { usize, usize } {
|
||||||
const char = whitespace.char;
|
const char = whitespace.char;
|
||||||
const colcount = 1 + self.tab_width - (abs_col % self.tab_width);
|
const colcount = self.tab_width - (abs_col % self.tab_width);
|
||||||
_ = n.cell_load(c, char.blank) catch {};
|
_ = n.cell_load(c, char.blank) catch {};
|
||||||
return .{ 1, colcount };
|
return .{ 1, colcount };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue