fix: don't reverse insert pairs when selection is reversed

closes #204
This commit is contained in:
CJ van den Berg 2025-03-18 16:25:52 +01:00
parent 47a6024c80
commit 8a0e048674
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -4143,10 +4143,14 @@ pub const Editor = struct {
var root = b.root;
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
if (cursel.selection) |*sel| {
const chars_begin, const chars_end = if (sel.is_reversed())
.{ chars_right, chars_left }
else
.{ chars_left, chars_right };
var begin: CurSel = .{ .cursor = sel.begin };
root = try self.insert(root, &begin, chars_left, b.allocator);
root = try self.insert(root, &begin, chars_begin, b.allocator);
var end: CurSel = .{ .cursor = sel.end };
root = try self.insert(root, &end, chars_right, b.allocator);
root = try self.insert(root, &end, chars_end, b.allocator);
sel.end.move_left(root, self.metrics) catch {};
} else blk: {
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
@ -4180,11 +4184,14 @@ pub const Editor = struct {
var root = b.root;
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
if (cursel.selection) |*sel| {
const chars_begin, const chars_end = if (sel.is_reversed())
.{ chars_right, chars_left }
else
.{ chars_left, chars_right };
var begin: CurSel = .{ .cursor = sel.begin };
root = try self.insert(root, &begin, chars_left, b.allocator);
root = try self.insert(root, &begin, chars_begin, b.allocator);
var end: CurSel = .{ .cursor = sel.end };
root = try self.insert(root, &end, chars_right, b.allocator);
sel.begin.move_left(root, self.metrics) catch {};
root = try self.insert(root, &end, chars_end, b.allocator);
cursel.disable_selection(root, self.metrics);
} else blk: {
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {