feat: add support for groups in clipboard history
This introduces the concept of clipboard history groups. A group is created for each high level clipboard operation. Cut, copy, etc. Single cursor operations will create a group with just one entry. Multi-cursor operations on the other hand will create groups with multiple clipboard history entries. This makes for very powerful clipboard history integration with multi-cursor support. This commit also adds the ability to apply integer parmeters to the paste command to select a clipboard group to paste. Also, pasting from the system clipboard will detect if the system clipboard is equivalent to the top most clipboard group, and if so use the group instead. This allows much better multi-cursor support when using the system copy & paste commands.
This commit is contained in:
parent
6f57578925
commit
4d375d2d9b
5 changed files with 174 additions and 73 deletions
|
|
@ -1409,7 +1409,11 @@ pub fn write_restore_info(self: *Self) void {
|
|||
|
||||
if (tui.clipboard_get_history()) |clipboard| {
|
||||
cbor.writeArrayHeader(writer, clipboard.len) catch return;
|
||||
for (clipboard) |item| cbor.writeValue(writer, item) catch return;
|
||||
for (clipboard) |item| {
|
||||
cbor.writeArrayHeader(writer, 2) catch return;
|
||||
cbor.writeValue(writer, item.group) catch return;
|
||||
cbor.writeValue(writer, item.text) catch return;
|
||||
}
|
||||
} else {
|
||||
cbor.writeValue(writer, null) catch return;
|
||||
}
|
||||
|
|
@ -1443,11 +1447,18 @@ fn read_restore_info(self: *Self) !void {
|
|||
|
||||
tui.clipboard_clear_all();
|
||||
var len = try cbor.decodeArrayHeader(&iter);
|
||||
var prev_group: usize = 0;
|
||||
const clipboard_allocator = tui.clipboard_allocator();
|
||||
while (len > 0) : (len -= 1) {
|
||||
var chunk: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract(&chunk))) return error.Stop;
|
||||
tui.clipboard_add_chunk(try clipboard_allocator.dupe(u8, chunk));
|
||||
const len_ = try cbor.decodeArrayHeader(&iter);
|
||||
if (len_ != 2) return error.Stop;
|
||||
var group: usize = 0;
|
||||
var text: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract(&group))) return error.Stop;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract(&text))) return error.Stop;
|
||||
if (prev_group != group) tui.clipboard_start_group();
|
||||
prev_group = group;
|
||||
tui.clipboard_add_chunk(try clipboard_allocator.dupe(u8, text));
|
||||
}
|
||||
|
||||
try self.buffer_manager.extract_state(&iter);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue