summaryrefslogtreecommitdiff
path: root/core/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/edit.zig')
-rw-r--r--core/edit.zig18
1 files changed, 13 insertions, 5 deletions
diff --git a/core/edit.zig b/core/edit.zig
index 6c0ba02b..e68f8d38 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -2140,6 +2140,9 @@ fn stepOwn(e: Editor, t: *Text, back: bool) error{OutOfMemory}!void {
const PointerTextSelection = struct {
sel: Pane.Sel,
on_tag: bool,
+ /// On a row of a message's detail (Pane.textRow): that body row as
+ /// drawn; the selection is on the line it explains.
+ ghost: ?u16 = null,
};
pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) ?PointerTextSelection {
@@ -2158,16 +2161,21 @@ pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, bod
if (!on_tag) if (body_hit) |supplied| {
const mapped_hit = mouse.bodyHitForPane(p, id, supplied, false) orelse return null;
const c = @as(i32, mapped_hit.col) - config.GUTTER;
- const v = @as(i32, mapped_hit.row) + pane.tag_rows;
- return .{ .sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v }, .on_tag = false };
+ const drawn: i32 = mapped_hit.row;
+ const v = pane.textRow(drawn) + pane.tag_rows;
+ const ghost = pane.ghost_rows > 0 and drawn > pane.ghost_at and drawn <= pane.ghost_at + pane.ghost_rows;
+ return .{ .sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v }, .on_tag = false, .ghost = if (ghost) mapped_hit.row else null };
};
const tag_col = if (on_tag) Layer.columnAt(p, .pane, id, tag_hit, false, row - tag_y) else null;
const c: i32 = (if (tag_col) |value| @as(i32, value) else @as(i32, col) - @as(i32, r.x + (if (on_tag) TAG_TEXT_INSET else config.GUTTER))) +
(if (on_tag) @as(i32, pane.tag_scroll) else 0);
- const v: i32 = if (on_tag) @as(i32, row) - @as(i32, tag_y) else @as(i32, row) - @as(i32, body_y) + @as(i32, pane.tag_rows);
+ const drawn: i32 = @as(i32, row) - @as(i32, body_y);
+ const v: i32 = if (on_tag) @as(i32, row) - @as(i32, tag_y) else pane.textRow(drawn) + @as(i32, pane.tag_rows);
+ const ghost = !on_tag and pane.ghost_rows > 0 and drawn > pane.ghost_at and drawn <= pane.ghost_at + pane.ghost_rows;
return .{
.sel = .{ .state = .dragging, .c0 = c, .c1 = c, .r0 = v, .r1 = v },
.on_tag = on_tag,
+ .ghost = if (ghost) @intCast(drawn) else null,
};
}
@@ -2320,7 +2328,7 @@ test "insert on a terminal's text says it edits a copy the program's next drawin
pane.body.mode = .normal;
p.update(.{ .key = .{ .cp = 'i' } });
p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "a copy of the terminal's text") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "a copy of the terminal's text") != null);
}
test "insert and normal modes edit complete Unicode graphemes" {
@@ -2533,7 +2541,7 @@ test "a paste past the limit is cut at it, and says so" {
try applyPaste(p, big);
try std.testing.expect(pane.file.?.content.len <= limit);
try std.testing.expect(pane.file.?.content.len > 0);
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "paste cut") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "paste cut") != null);
}
test "typing and backspace through the line index keep the text and the index as a rebuild has them" {