fix: unicode symbol rendering in symbol palette
This commit is contained in:
parent
6187bc5191
commit
3886427582
4 changed files with 26 additions and 82 deletions
|
|
@ -183,6 +183,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
theme,
|
theme,
|
||||||
if (values.label_detail.len > detail_limit) "…" else "",
|
if (values.label_detail.len > detail_limit) "…" else "",
|
||||||
if (values.label_description.len > description_limit) "…" else "",
|
if (values.label_description.len > description_limit) "…" else "",
|
||||||
|
&.{},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
theme,
|
theme,
|
||||||
&.{},
|
&.{},
|
||||||
&.{},
|
&.{},
|
||||||
|
&.{},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ const cbor = @import("cbor");
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
const root = @import("soft_root").root;
|
const root = @import("soft_root").root;
|
||||||
const text_manip = @import("text_manip");
|
const text_manip = @import("text_manip");
|
||||||
const write_string = text_manip.write_string;
|
|
||||||
const write_padding = text_manip.write_padding;
|
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const Buffer = @import("Buffer");
|
const Buffer = @import("Buffer");
|
||||||
const SymbolKind = @import("lsp_types").SymbolKind;
|
const SymbolKind = @import("lsp_types").SymbolKind;
|
||||||
|
|
@ -23,22 +21,6 @@ pub const icon = " ";
|
||||||
pub const modal_dim = false;
|
pub const modal_dim = false;
|
||||||
pub const placement = .top_right;
|
pub const placement = .top_right;
|
||||||
|
|
||||||
const Column = struct {
|
|
||||||
label: []const u8,
|
|
||||||
max_width: u8,
|
|
||||||
min_width: u8,
|
|
||||||
};
|
|
||||||
const ColumnName = enum(u8) {
|
|
||||||
Name = 0,
|
|
||||||
Container = 1,
|
|
||||||
Kind = 2,
|
|
||||||
};
|
|
||||||
const columns: [3]Column = .{
|
|
||||||
.{ .label = "Name", .max_width = 26, .min_width = 4 },
|
|
||||||
.{ .label = "Container", .max_width = 14, .min_width = 4 },
|
|
||||||
.{ .label = "Kind", .max_width = 12, .min_width = 4 },
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Entry = struct {
|
pub const Entry = struct {
|
||||||
label: []const u8,
|
label: []const u8,
|
||||||
range: ed.Selection,
|
range: ed.Selection,
|
||||||
|
|
@ -48,52 +30,9 @@ pub const Entry = struct {
|
||||||
pub const ValueType = struct {
|
pub const ValueType = struct {
|
||||||
start: ed.CurSel = .{},
|
start: ed.CurSel = .{},
|
||||||
view: ed.View = .{},
|
view: ed.View = .{},
|
||||||
column_size: [3]u8 = undefined,
|
|
||||||
};
|
};
|
||||||
pub const defaultValue: ValueType = .{};
|
pub const defaultValue: ValueType = .{};
|
||||||
|
|
||||||
fn init_col_sizes(palette: *Type) void {
|
|
||||||
for (0..columns.len) |i| {
|
|
||||||
palette.value.column_size[i] = columns[i].min_width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_min_col_sizes(palette: *Type) void {
|
|
||||||
for (0..columns.len) |i| {
|
|
||||||
palette.value.column_size[i] = @min(columns[i].max_width, palette.value.column_size[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_max_col_sizes(palette: *Type, comp_sizes: []const usize) u8 {
|
|
||||||
var total_length: u8 = 0;
|
|
||||||
for (0..columns.len) |i| {
|
|
||||||
const truncated: u8 = @truncate(comp_sizes[i]);
|
|
||||||
palette.value.column_size[i] = @max(if (truncated > columns[i].max_width) columns[i].max_width else truncated, palette.value.column_size[i]);
|
|
||||||
total_length += palette.value.column_size[i];
|
|
||||||
}
|
|
||||||
return total_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_columns(palette: *Type, writer: *std.Io.Writer, column_info: [][]const u8) void {
|
|
||||||
if (palette.value.column_size.len == 0)
|
|
||||||
return;
|
|
||||||
write_string(writer, column_info[0][0..@min(palette.value.column_size[0], column_info[0].len)], columns[0].max_width) catch {};
|
|
||||||
|
|
||||||
for (1..column_info.len) |i| {
|
|
||||||
write_padding(writer, 1, 2) catch {};
|
|
||||||
write_string(writer, column_info[i][0..@min(palette.value.column_size[i], column_info[i].len)], columns[i].max_width) catch {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn total_row_width() u8 {
|
|
||||||
var total_width: u8 = 0;
|
|
||||||
|
|
||||||
for (columns) |col| {
|
|
||||||
total_width += col.max_width;
|
|
||||||
}
|
|
||||||
return total_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_entries(palette: *Type) !usize {
|
pub fn load_entries(palette: *Type) !usize {
|
||||||
const mv = tui.mainview() orelse return 0;
|
const mv = tui.mainview() orelse return 0;
|
||||||
const editor = tui.get_active_editor() orelse return error.NotFound;
|
const editor = tui.get_active_editor() orelse return error.NotFound;
|
||||||
|
|
@ -103,21 +42,17 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
palette.value.start = editor.get_primary().*;
|
palette.value.start = editor.get_primary().*;
|
||||||
palette.value.view = editor.view;
|
palette.value.view = editor.view;
|
||||||
var iter: []const u8 = mv.symbols.items;
|
var iter: []const u8 = mv.symbols.items;
|
||||||
init_col_sizes(palette);
|
|
||||||
while (iter.len > 0) {
|
while (iter.len > 0) {
|
||||||
var cbor_item: []const u8 = undefined;
|
var cbor_item: []const u8 = undefined;
|
||||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||||
const label_, const parent_, const kind, const sel = get_values(cbor_item);
|
const label_, _, _, const sel = get_values(cbor_item);
|
||||||
const label_len_ = tui.egc_chunk_width(label_, 0, 1);
|
const label_len_ = tui.egc_chunk_width(label_, 0, 1);
|
||||||
const parent_len = tui.egc_chunk_width(parent_, 0, 1);
|
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_, .range = sel };
|
||||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .range = sel };
|
|
||||||
|
|
||||||
const current_lengths: [3]usize = .{ label_len_, parent_len, @tagName(kind).len };
|
const label_len: u8 = @truncate(label_len_);
|
||||||
const label_len: u8 = @truncate(if (label_len_ > columns[0].max_width) columns[0].max_width else label_len_);
|
max_cols_len = @max(max_cols_len, label_len);
|
||||||
max_cols_len = @max(max_cols_len, label_len, update_max_col_sizes(palette, ¤t_lengths));
|
|
||||||
max_label_len = @max(max_label_len, label_len);
|
max_label_len = @max(max_label_len, label_len);
|
||||||
}
|
}
|
||||||
update_min_col_sizes(palette);
|
|
||||||
|
|
||||||
const less_fn = struct {
|
const less_fn = struct {
|
||||||
fn less_fn(_: void, lhs: Entry, rhs: Entry) bool {
|
fn less_fn(_: void, lhs: Entry, rhs: Entry) bool {
|
||||||
|
|
@ -129,9 +64,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
palette.initial_selected = find_closest(palette);
|
palette.initial_selected = find_closest(palette);
|
||||||
palette.quick_activate_enabled = false;
|
palette.quick_activate_enabled = false;
|
||||||
|
|
||||||
const total_width = total_row_width();
|
return 5 + max_label_len;
|
||||||
const outer_label_len = tui.egc_chunk_width(label, 0, 1);
|
|
||||||
return 2 + if (max_cols_len > outer_label_len + 3) total_width - max_label_len else outer_label_len + 1 - max_cols_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_entries(palette: *Type) void {
|
pub fn clear_entries(palette: *Type) void {
|
||||||
|
|
@ -148,7 +81,7 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Widget.Theme, selected: bool) bool {
|
pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.Theme, selected: bool) bool {
|
||||||
var item_cbor: []const u8 = undefined;
|
var item_cbor: []const u8 = undefined;
|
||||||
var matches_cbor: []const u8 = undefined;
|
var matches_cbor: []const u8 = undefined;
|
||||||
|
|
||||||
|
|
@ -159,14 +92,22 @@ pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Wi
|
||||||
const label_, const container, const kind, _ = get_values(item_cbor);
|
const label_, const container, const kind, _ = get_values(item_cbor);
|
||||||
const icon_: []const u8 = kind.icon();
|
const icon_: []const u8 = kind.icon();
|
||||||
const color: u24 = 0x0;
|
const color: u24 = 0x0;
|
||||||
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
return tui.render_symbol(
|
||||||
defer value.deinit();
|
&button.plane,
|
||||||
const writer = &value.writer;
|
label_,
|
||||||
var column_info = [_][]const u8{ label_, container, @tagName(kind) };
|
icon_,
|
||||||
write_columns(palette, writer, &column_info);
|
color,
|
||||||
const indicator: []const u8 = &.{};
|
container,
|
||||||
|
@tagName(kind),
|
||||||
return tui.render_file_item(&button.plane, value.written(), icon_, color, indicator, &.{}, matches_cbor, button.active, selected, button.hover, theme);
|
matches_cbor,
|
||||||
|
button.active,
|
||||||
|
selected,
|
||||||
|
button.hover,
|
||||||
|
theme,
|
||||||
|
&.{},
|
||||||
|
&.{},
|
||||||
|
if (container.len > 0) " → " else &.{},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection } {
|
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection } {
|
||||||
|
|
|
||||||
|
|
@ -2183,6 +2183,7 @@ pub fn render_symbol(
|
||||||
theme_: *const Widget.Theme,
|
theme_: *const Widget.Theme,
|
||||||
detail_suffix: []const u8,
|
detail_suffix: []const u8,
|
||||||
description_suffix: []const u8,
|
description_suffix: []const u8,
|
||||||
|
detail_prefix: []const u8,
|
||||||
) bool {
|
) bool {
|
||||||
const style_base = theme_.editor_widget;
|
const style_base = theme_.editor_widget;
|
||||||
const style_symbol = if (active) theme_.editor_cursor else if (hover or selected) theme_.editor_selection else theme_.editor_widget;
|
const style_symbol = if (active) theme_.editor_cursor else if (hover or selected) theme_.editor_selection else theme_.editor_widget;
|
||||||
|
|
@ -2206,7 +2207,7 @@ pub fn render_symbol(
|
||||||
_ = self.print("{s}", .{symbol}) catch {};
|
_ = self.print("{s}", .{symbol}) catch {};
|
||||||
|
|
||||||
self.set_style(style_detail);
|
self.set_style(style_detail);
|
||||||
_ = self.print("{s}{s}", .{ detail, detail_suffix }) catch {};
|
_ = self.print("{s}{s}{s}", .{ detail_prefix, detail, detail_suffix }) catch {};
|
||||||
|
|
||||||
var lines = std.mem.splitScalar(u8, description, '\n');
|
var lines = std.mem.splitScalar(u8, description, '\n');
|
||||||
if (lines.next()) |desc| {
|
if (lines.next()) |desc| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue