diff options
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/exec.zig b/src/exec.zig index a0e3d47f..46b4f57b 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -210,10 +210,18 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { return null; } +/// A clicked word and the selection held for it, as one command line. pub fn withArg(p: *Pardes, txt: []const u8, arg: ?[]const u8) []const u8 { const a = std.mem.trim(u8, arg orelse return txt, " \t\r\n"); if (a.len == 0) return txt; const t = std.mem.trim(u8, txt, " \t\r\n"); + // A switch (Verbose, PanelSlide, Crt) clicked with some other text + // selected flips, as it does bare: only `on` or `off` is an argument + // for it. What a ctl write gives it is checked strictly instead. + if (config.Runtime.find(commandText(t))) |setting| switch (setting.action) { + .toggle, .transition, .scene => if (!std.mem.eql(u8, a, "on") and !std.mem.eql(u8, a, "off")) return txt, + else => {}, + }; return std.fmt.allocPrint(p.scratch.allocator(), "{s} {s}", .{ t, a }) catch txt; } @@ -567,3 +575,18 @@ test "the acme chords act once per selection, not once on the primary" { // ...and the chord consumed the selection exactly as it does with one. try std.testing.expectEqual(@as(u8, 0), p.panes[0].?.body.nsel); } + +test "a switch clicked with a selection held flips unless the selection says on or off" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + const before = p.settings.verbose; + _ = execute(p, p.active, withArg(p, "Verbose", "some selected text")); + try std.testing.expectEqual(!before, p.settings.verbose); + _ = execute(p, p.active, withArg(p, "Verbose", "on")); + try std.testing.expect(p.settings.verbose); + _ = execute(p, p.active, withArg(p, "Verbose", " off\n")); + try std.testing.expect(!p.settings.verbose); + // A word that takes any argument still gets the selection. + try std.testing.expectEqualStrings("Msg some text", withArg(p, "Msg", "some text")); +} |
