summaryrefslogtreecommitdiff
path: root/src/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.zig')
-rw-r--r--src/edit.zig44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 5adb94e3..c6c59604 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -35,7 +35,7 @@ const Registers = pardes.Registers;
/// registers computed from the editor (`#`, `.`, `%`) cannot be written.
/// `+` and `*` are the system clipboard: the value is sent there too.
pub fn setYank(p: *Pardes, text: []const u8) void {
- var name: u21 = if (p.register != 0) p.register else Registers.default;
+ var name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
switch (name) {
'_', '#', '.', '%' => return,
'*' => name = '+',
@@ -75,7 +75,7 @@ fn selText(p: *Pardes, t: *Text) []const u8 {
pub const Paste = enum { after, before, replace };
pub fn pasteRegister(p: *Pardes, t: *Text, how: Paste, count: usize) void {
- const name: u21 = if (p.register != 0) p.register else Registers.default;
+ const name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
if (name == '+' or name == '*') {
if (!normal.multiOnce(p)) return;
const pane = t.pane() orelse return;
@@ -98,7 +98,7 @@ pub const ClipRequest = struct {
pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void {
const pane = p.panes[id] orelse return;
- p.clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
+ p.view().clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
p.emit(.read_clipboard);
}
@@ -111,27 +111,28 @@ pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) voi
}
pub fn applyPaste(p: *Pardes, whole: []const u8) void {
+ const v = p.view();
// Every shell's paste comes through here, bounded: what is past the
// limit is left out, at a character's start, and said.
const limit = @import("memory.zig").limits.max_paste_bytes;
const bytes = if (whole.len > limit) whole[0..modal.graphemeStart(whole, limit)] else whole;
if (whole.len > limit) {
var said: [96]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
+ p.setMessage(v.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
}
// A prompt answering for a header takes the paste, as it takes keys.
- const asking = if (p.panes[p.active]) |active| active.prompt != .none else false;
+ const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking) if (tagline.focusedHeader(p)) |t| {
- p.clip_pending = null;
+ v.clip_pending = null;
return pasteInto(p, t, bytes);
};
- const req = p.clip_pending;
- p.clip_pending = null;
+ const req = v.clip_pending;
+ v.clip_pending = null;
if (bytes.len == 0) return;
- const id = if (req) |r| r.pane else p.active;
+ const id = if (req) |r| r.pane else v.active;
const pane = p.panes[id] orelse return;
if (req) |r| if (pane.serial != r.serial) return;
- p.active = id;
+ v.active = id;
if (pane.prompt != .none and pane.prompt != .del_side and pane.prompt != .repl_choice) {
// an answer is one line: a newline in it would only be submitting it
const line = p.scratch.allocator().alloc(u8, bytes.len) catch return;
@@ -172,10 +173,11 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void {
}
pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void {
+ const v = p.view();
// helix's `"+y`: the clipboard register, and only it
- const named = p.register;
- p.register = '+';
- defer p.register = named;
+ const named = v.register;
+ v.register = '+';
+ defer v.register = named;
if (comptime pdf_enabled) if (pane.pdf) |pv| {
if (pv.selection_text.len > 0) setYank(p, pv.selection_text);
return;
@@ -350,7 +352,7 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool {
/// the active modal selection as text, if any
pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 {
- if (comptime pdf_enabled) if (p.frontend.native_images) if (pane.pdf) |pv|
+ if (comptime pdf_enabled) if (p.view().frontend.native_images) if (pane.pdf) |pv|
if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text;
if (!pane.body.vsel.active) return null;
return vselText(p, &pane.body);
@@ -1027,7 +1029,7 @@ fn insertEdit(p: *Pardes, t: *Text, key: Key) void {
const f = (t.pane() orelse break :dot).file orelse break :dot;
if (f.output != null or !lsp.speaks(f.path)) break :dot;
const seq = p.lsp_ask.seq;
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
if (p.lsp_ask.seq != seq) return;
}
// helix smart_tab: after text, Tab leaves the syntax node the
@@ -1845,7 +1847,7 @@ pub fn pushUndo(p: *Pardes, t: *Text) void {
if (!p.multi_first) return;
switch (t.what) {
// A B1 chord took its one undo point when it began (mouse.zig).
- .body => if (p.chord_hold) return,
+ .body => if (p.view().chord_hold) return,
.tag, .column, .workspace => return t.remember(p.gpa, if (t.own) |own| .{ .text = own } else null),
// a prompt's answer is typed once and gone; it keeps no history
.input => return,
@@ -1880,7 +1882,7 @@ const PointerTextSelection = struct {
pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) ?PointerTextSelection {
const pane = p.panes[id] orelse return null;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (col < r.x + config.GUTTER or col >= r.x + r.w or row < r.y or row >= r.y + r.h) return null;
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
@@ -2063,11 +2065,11 @@ test "only the SPC clipboard commands cross to the system clipboard" {
const before = pane.file.?.content.len;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'p' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
try std.testing.expect(drainedEffect(p, .read_clipboard));
try std.testing.expectEqual(before, pane.file.?.content.len); // nothing yet
p.update(.{ .paste = "PASTED" });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "PASTED") != null);
// ...and it did NOT land in the register on its way past, nor echo back
// out to the clipboard it came from.
@@ -2084,9 +2086,9 @@ test "only the SPC clipboard commands cross to the system clipboard" {
// than firing late into whatever pane is focused by then.
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'P' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
p.update(.{ .key = .{ .cp = 'l' } });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
}
/// acme's double-click (plan9port acme text.c:1407, textdoubleclick): from