summaryrefslogtreecommitdiff
path: root/core/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/edit.zig')
-rw-r--r--core/edit.zig27
1 files changed, 21 insertions, 6 deletions
diff --git a/core/edit.zig b/core/edit.zig
index 8ed7752e..e68f8d38 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -124,6 +124,11 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
var said: pardes.Kind.Buf(96) = .{};
p.setMessage(.at(v.active), said.print("paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}));
}
+ // A text prompt in a tag takes it into its field (Prompt.zig).
+ if (v.tag_state.kind == .prompt) {
+ v.clip_pending = null;
+ return pardes.Prompt.paste(p, bytes);
+ }
// A prompt answering for a header takes the paste, as it takes keys.
const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking) if (tagline.focusedHeader(p)) |t| {
@@ -146,7 +151,9 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
n += 1;
};
if (n > 0) try insertKey(p.editor(), &pane.input, .{ .cp = line[0], .text = line[0..n] });
- if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |t| {
+ _ = normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ };
return;
}
if (pane.focus == .tag) return pasteInto(p, &pane.tag, bytes);
@@ -2133,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 {
@@ -2151,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,
};
}
@@ -2313,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" {
@@ -2526,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" {