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;
|
var max_description: usize = 0;
|
||||||
|
|
||||||
pub fn load_entries(palette: *Type) !usize {
|
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;
|
const editor = tui.get_active_editor() orelse return error.NotFound;
|
||||||
palette.value.start = editor.get_primary().*;
|
palette.value.start = editor.get_primary().*;
|
||||||
var iter: []const u8 = editor.completions.items;
|
var iter: []const u8 = editor.completions.items;
|
||||||
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;
|
||||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = undefined, .sort_text = undefined };
|
const values = get_values(cbor_item);
|
||||||
}
|
|
||||||
|
|
||||||
max_description = 0;
|
|
||||||
var max_label_len: usize = 0;
|
|
||||||
for (palette.entries.items) |*item| {
|
|
||||||
const values = get_values(item.cbor);
|
|
||||||
if (palette.value.replace == null) if (get_replace_selection(values.replace)) |replace| {
|
if (palette.value.replace == null) if (get_replace_selection(values.replace)) |replace| {
|
||||||
palette.value.replace = replace;
|
palette.value.replace = replace;
|
||||||
};
|
};
|
||||||
item.label = values.label;
|
const item = (try palette.entries.addOne(palette.allocator));
|
||||||
item.sort_text = values.sort_text;
|
item.* = .{
|
||||||
|
.cbor = cbor_item,
|
||||||
|
.label = values.label,
|
||||||
|
.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 = if (lines.next()) |desc| desc.len else values.label_description.len;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue