summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 16:08:36 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commit062523f4684e81715dec844bb1983b7bde7df5fc (patch)
tree7c998a7636ffb66d66a1ee6cf6f6bdc021b0e683 /src/pardes.zig
parentffef5a511a14071bd9be9887439a6cb40af3fb92 (diff)
downloadpardes-062523f4684e81715dec844bb1983b7bde7df5fc.tar.gz
pardes-062523f4684e81715dec844bb1983b7bde7df5fc.zip
Whether an exec came from a body travels with it, so every selection goes to the REPL
The execute key and the middle click marked a global flag that the first execute cleared, so of several selections executed at once only the first reached a bound REPL and the rest ran as commands. Where an exec came from now goes with it, as acme's execute() asks of its Text (exec.c:122,169): builtins.Ctx carries from_body, runBuiltinFrom and executeFrom take it, the gestures set it, and chordEachSel sets it for each selection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 12de47fa..872ea171 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1465,16 +1465,22 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
Sent.drain(p);
// A click on the file's body, a single word: typed into the REPL.
- p.exec_from_body = true;
- try std.testing.expectEqual(@as(?usize, 1), exec.execute(p, 0, "ls"));
+ try std.testing.expectEqual(@as(?usize, 1), exec.executeFrom(p, 0, "ls", true));
Sent.drain(p);
try std.testing.expectEqualStrings("ls\r", Sent.said(1));
try std.testing.expect(!Sent.spawned);
try std.testing.expect(file.msg_sent);
try std.testing.expectEqualStrings("\u{2192} python-a", file.msg[0..file.msg_len]);
+ // Several selections executed at once: each is sent, not the first.
+ {
+ const text = try edit.flatSurface(p, &file.body);
+ file.body.setRanges(text, &.{ .{ .anchor = 0, .head = 8 }, .{ .anchor = 9, .head = 11 } }, &.{}, 0, true);
+ try std.testing.expect(exec.chordEachSel(p, file, .Exec));
+ Sent.drain(p);
+ try std.testing.expectEqualStrings("print(1)\rls\r", Sent.said(1));
+ }
// Its own body too.
- p.exec_from_body = true;
- try std.testing.expectEqual(@as(?usize, 1), exec.execute(p, 1, "x = 1"));
+ try std.testing.expectEqual(@as(?usize, 1), exec.executeFrom(p, 1, "x = 1", true));
Sent.drain(p);
try std.testing.expectEqualStrings("x = 1\r", Sent.said(1));
@@ -1485,8 +1491,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(p.executeBuiltinLine(0, "Exec ls"));
Sent.drain(p);
try std.testing.expect(Sent.spawned and Sent.len[1] == 0);
- p.exec_from_body = true;
- _ = exec.execute(p, 0, "@`ls`");
+ _ = exec.executeFrom(p, 0, "@`ls`", true);
Sent.drain(p);
try std.testing.expect(Sent.spawned and Sent.len[1] == 0);
@@ -1494,16 +1499,14 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(p.executeBuiltinLine(2, "Repl python"));
try std.testing.expectEqualStrings("python-b", exec.replId(&idbuf, p.panes[2].?));
Sent.drain(p);
- p.exec_from_body = true;
- try std.testing.expectEqual(@as(?usize, null), exec.execute(p, 0, "print(2)"));
+ try std.testing.expectEqual(@as(?usize, null), exec.executeFrom(p, 0, "print(2)", true));
try std.testing.expectEqual(Pane.Prompt.repl_choice, file.prompt);
try std.testing.expect(std.mem.indexOf(u8, file.promptText().?, "a b") != null);
p.update(.{ .key = .{ .cp = 'b' } });
Sent.drain(p);
try std.testing.expectEqualStrings("print(2)\r", Sent.said(2));
try std.testing.expect(Sent.len[1] == 0 and file.prompt == .none);
- p.exec_from_body = true;
- _ = exec.execute(p, 0, "print(3)");
+ _ = exec.executeFrom(p, 0, "print(3)", true);
p.update(.{ .key = .{ .cp = Key.escape } });
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0);
@@ -1512,8 +1515,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
// sent nothing, and nothing runs: it says so.
host.taken[1] = false;
host.taken[2] = false;
- p.exec_from_body = true;
- _ = exec.execute(p, 0, "import os");
+ _ = exec.executeFrom(p, 0, "import os", true);
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0 and !Sent.spawned);
try std.testing.expect(std.mem.indexOf(u8, file.msg[0..file.msg_len], "no program running") != null);
@@ -4121,10 +4123,6 @@ pub const Pardes = struct {
chord_arg: ?[]u8 = null,
/// how many `execute` calls are on the stack — see max_exec_depth
exec_depth: u8 = 0,
- /// The exec under way was made by a gesture on a pane's body -- a
- /// middle click, the execute key -- and so may go to a REPL bound for
- /// the text's language; one run by name, `Exec ...`, never does.
- exec_from_body: bool = false,
/// An exec waiting on the REPL question (`Pane.Prompt.repl_choice`):
/// the pane it came from, the language, and the text, owned.
repl_ask: ?struct { from: u32, lang: u8, text: []u8 } = null,
@@ -5380,9 +5378,6 @@ pub const Pardes = struct {
return;
}
edit.pinPaneCursor(p, &pane.body);
- // The execute key on a body is the exec a bound REPL may take.
- p.exec_from_body = cmd == config.exec_cmd;
- defer p.exec_from_body = false;
const explicit = (p.native_images and pane.hasPdfSelection()) or
(pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active;
if (explicit) {
@@ -5391,13 +5386,14 @@ pub const Pardes = struct {
pane.body.vsel.active = false;
pane.body.msel.active = false;
pane.body.select = false;
- exec.runBuiltin(p, cmd, p.active, "", txt);
+ // The execute key on a body: text a bound REPL may take.
+ exec.runBuiltinFrom(p, cmd, p.active, "", txt, true);
return;
}
}
const sel = look.expandedSel(p, pane, look.cursorWordSel(p, pane)) orelse return;
const word = edit.selectionText(p, pane, sel) catch return;
- exec.runBuiltin(p, cmd, p.active, "", word);
+ exec.runBuiltinFrom(p, cmd, p.active, "", word, true);
return;
}
if (t.mode == .normal and t.what == .body and pane.hasPdf()) return normal.handlePdfNormal(p, pane, key);