refactor: merge loops in completion_palette.load_entries
This commit is contained in:
parent
93bfc70171
commit
7dab15da20
1 changed files with 10 additions and 9 deletions
|
|
@ -35,24 +35,25 @@ pub const defaultValue: ValueType = .{};
|
|||
var max_description: usize = 0;
|
||||
|
||||
pub fn load_entries(palette: *Type) !usize {
|
||||
max_description = 0;
|
||||
var max_label_len: usize = 0;
|
||||
|
||||
const editor = tui.get_active_editor() orelse return error.NotFound;
|
||||
palette.value.start = editor.get_primary().*;
|
||||
var iter: []const u8 = editor.completions.items;
|
||||
while (iter.len > 0) {
|
||||
var cbor_item: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = undefined, .sort_text = undefined };
|
||||
}
|
||||
|
||||
max_description = 0;
|
||||
var max_label_len: usize = 0;
|
||||
for (palette.entries.items) |*item| {
|
||||
const values = get_values(item.cbor);
|
||||
const values = get_values(cbor_item);
|
||||
if (palette.value.replace == null) if (get_replace_selection(values.replace)) |replace| {
|
||||
palette.value.replace = replace;
|
||||
};
|
||||
item.label = values.label;
|
||||
item.sort_text = values.sort_text;
|
||||
const item = (try palette.entries.addOne(palette.allocator));
|
||||
item.* = .{
|
||||
.cbor = cbor_item,
|
||||
.label = values.label,
|
||||
.sort_text = values.sort_text,
|
||||
};
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue