diff --git a/src/tui/mode/overlay/clipboard_palette.zig b/src/tui/mode/overlay/clipboard_palette.zig index 1bd2da3..c4b770e 100644 --- a/src/tui/mode/overlay/clipboard_palette.zig +++ b/src/tui/mode/overlay/clipboard_palette.zig @@ -24,8 +24,13 @@ pub fn load_entries(palette: *Type) !usize { if (history.len > 0) { var idx = history.len - 1; while (true) : (idx -= 1) { + var label_ = history[idx]; + while (label_.len > 0) switch (label_[0]) { + ' ', '\t', '\n' => label_ = label_[1..], + else => break, + }; (try palette.entries.addOne(palette.allocator)).* = .{ - .label = history[idx], + .label = label_, .idx = idx, }; if (idx == 0) break; @@ -46,14 +51,15 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v var hint: std.Io.Writer.Allocating = .init(palette.allocator); defer hint.deinit(); + const item = if (tui.clipboard_get_history()) |clipboard| clipboard[entry.idx] else &.{}; var line_count: usize = 1; - for (0..entry.label.len) |i| if (entry.label[i] == '\n') { + for (0..item.len) |i| if (item[i] == '\n') { line_count += 1; }; if (line_count > 1) try hint.writer.print(" {d} lines", .{line_count}) else - try hint.writer.print(" {d} {s}", .{ entry.label.len, if (entry.label.len == 1) "byte" else "bytes" }); + try hint.writer.print(" {d} {s}", .{ item.len, if (item.len == 1) "byte " else "bytes" }); try cbor.writeValue(writer, hint.written()); try cbor.writeValue(writer, matches orelse &[_]usize{});