refactor: limit maximum size of detail and description in completion dropdown
This commit is contained in:
parent
b5d137666f
commit
f875dba810
3 changed files with 14 additions and 6 deletions
|
|
@ -20,6 +20,8 @@ pub const icon = " ";
|
||||||
pub const modal_dim = false;
|
pub const modal_dim = false;
|
||||||
pub const placement = .primary_cursor;
|
pub const placement = .primary_cursor;
|
||||||
pub const widget_type: Widget.Type = .dropdown;
|
pub const widget_type: Widget.Type = .dropdown;
|
||||||
|
pub var detail_limit: usize = 40;
|
||||||
|
pub var description_limit: usize = 25;
|
||||||
|
|
||||||
pub const Entry = struct {
|
pub const Entry = struct {
|
||||||
label: []const u8,
|
label: []const u8,
|
||||||
|
|
@ -58,10 +60,10 @@ pub fn load_entries(self: *Type) !usize {
|
||||||
item.sort_text = values.sort_text;
|
item.sort_text = values.sort_text;
|
||||||
|
|
||||||
var lines = std.mem.splitScalar(u8, values.label_description, '\n');
|
var lines = std.mem.splitScalar(u8, values.label_description, '\n');
|
||||||
const label_description_len = if (lines.next()) |desc| desc.len else values.label_description.len;
|
const label_description_len: usize = if (lines.next()) |desc| desc.len else values.label_description.len;
|
||||||
|
|
||||||
max_label_len = @max(max_label_len, item.label.len);
|
max_label_len = @max(max_label_len, item.label.len);
|
||||||
max_description = @max(max_description, label_description_len + values.label_detail.len);
|
max_description = @max(max_description, @min(label_description_len, description_limit) + @min(values.label_detail.len, detail_limit) + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const less_fn = struct {
|
const less_fn = struct {
|
||||||
|
|
@ -172,13 +174,15 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
values.label,
|
values.label,
|
||||||
icon_,
|
icon_,
|
||||||
color,
|
color,
|
||||||
values.label_detail,
|
values.label_detail[0..@min(values.label_detail.len, detail_limit)],
|
||||||
values.label_description,
|
values.label_description[0..@min(values.label_description.len, description_limit)],
|
||||||
matches_cbor,
|
matches_cbor,
|
||||||
button.active,
|
button.active,
|
||||||
selected,
|
selected,
|
||||||
button.hover,
|
button.hover,
|
||||||
theme,
|
theme,
|
||||||
|
if (values.label_detail.len > detail_limit) "…" else "",
|
||||||
|
if (values.label_description.len > description_limit) "…" else "",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,8 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
selected,
|
selected,
|
||||||
button.hover,
|
button.hover,
|
||||||
theme,
|
theme,
|
||||||
|
&.{},
|
||||||
|
&.{},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2167,6 +2167,8 @@ pub fn render_symbol(
|
||||||
selected: bool,
|
selected: bool,
|
||||||
hover: bool,
|
hover: bool,
|
||||||
theme_: *const Widget.Theme,
|
theme_: *const Widget.Theme,
|
||||||
|
detail_suffix: []const u8,
|
||||||
|
description_suffix: []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;
|
||||||
|
|
@ -2190,12 +2192,12 @@ 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}", .{detail}) catch {};
|
_ = self.print("{s}{s}", .{ 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| {
|
||||||
self.set_style(style_description);
|
self.set_style(style_description);
|
||||||
_ = self.print_right(" {s} ", .{desc}) catch {};
|
_ = self.print_right(" {s}{s} ", .{ desc, description_suffix }) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
var iter = matches_cbor;
|
var iter = matches_cbor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue