Add composable object selections
This commit is contained in:
@@ -370,6 +370,44 @@ pub const Session = struct {
|
||||
.active_panel_title = panel_state.active_title,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn moveToByte(self: *Session, byte: usize) !void {
|
||||
if (self.buffer) |*buffer| {
|
||||
if (byte > buffer.bytes.items.len) return error.SelectionOutOfBounds;
|
||||
buffer.cursor.byte = byte;
|
||||
buffer.refreshCell();
|
||||
return;
|
||||
}
|
||||
return error.NoActiveBuffer;
|
||||
}
|
||||
|
||||
pub fn selectRange(self: *Session, start: usize, end: usize) !void {
|
||||
if (self.buffer) |*buffer| {
|
||||
if (start > end or end > buffer.bytes.items.len) return error.SelectionOutOfBounds;
|
||||
buffer.selection = .{ .anchor = start, .cursor = end };
|
||||
buffer.cursor.byte = end;
|
||||
buffer.refreshCell();
|
||||
return;
|
||||
}
|
||||
return error.NoActiveBuffer;
|
||||
}
|
||||
|
||||
pub fn clearSelection(self: *Session) void {
|
||||
if (self.buffer) |*buffer| buffer.selection = null;
|
||||
}
|
||||
|
||||
pub fn replaceRange(self: *Session, start: usize, end: usize, bytes: []const u8) !void {
|
||||
if (!std.unicode.utf8ValidateSlice(bytes)) return error.InvalidUtf8Insertion;
|
||||
if (self.buffer) |*buffer| {
|
||||
if (start > end or end > buffer.bytes.items.len) return error.SelectionOutOfBounds;
|
||||
try buffer.bytes.replaceRange(buffer.allocator, start, end - start, bytes);
|
||||
buffer.cursor.byte = start + bytes.len;
|
||||
buffer.refreshCell();
|
||||
buffer.selection = null;
|
||||
return;
|
||||
}
|
||||
return error.NoActiveBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
fn isWordSeparator(byte: u8) bool {
|
||||
|
||||
Reference in New Issue
Block a user